Blogger Information
Blog 70
fans 4
comment 5
visits 104894
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP:【实战】用composer自撸框架
JiaJieChen
Original
704 people have browsed it

PHP:【实战】用composer自撸框架

自撸 PHP 发开框架

1.架构

  • M :MODEL, 使用第三方包实现
  • V :VIEW, 使用第三方包实现
  • C :CONTROLLER :业务逻辑是写在控制器中

2.第三方包

  • Model : composer require catfan/medoo
  • View : composer require league/plates

3. 流程

  • 创建自己的框架核心代码,MODEL, VIEW,分别继承第三方的包
  • 创建自己的应用, 按MVC架构模式,创建属于自己的models, views, controllers

一.Core框架核心类文件

①Model 模型类文件

②View 视图类文件

二.MVC框架类文件

①Model 模型类文件

②View 视图类文件

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="/static/css/style.css">
  9. </head>
  10. <body>
  11. <table>
  12. <caption>用户信息表</caption>
  13. <thead>
  14. <tr>
  15. <td>编号</td>
  16. <td>姓名</td>
  17. <td>性别</td>
  18. <td>操作</td>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <?php foreach($users as $user):?>
  23. <tr>
  24. <td><?= $user['id']?></td>
  25. <td><?= $user['uname']?></td>
  26. <td><?= $user['gender']==1?'男':'女'?></td>
  27. <td><button>删除</button><button>编辑</button></td>
  28. </tr>
  29. <?php endforeach;?>
  30. </tbody>
  31. </table>
  32. <?php
  33. //讨论省略点分页 前提: 两边的省略点都出现的时候
  34. //分页条显示的页数
  35. $showPages = 5;
  36. //分页条的开始页码值
  37. $startPage = 1;
  38. //分页条的结束页码值
  39. $endPage = $pages;
  40. //分页条的终止页码相对于当前页码的偏移量:
  41. $offset = ($showPages-1)/2;
  42. if($showPages < $pages)
  43. {
  44. if($page > $offset+1)
  45. {
  46. $startOmit = '...';
  47. $startPage = $page-$offset;
  48. $endPage = $page+$offset;
  49. if($endPage > $pages){$endPage=$pages;}
  50. }else{
  51. $startPage = 1;
  52. $endPage = $showPages;
  53. }
  54. if($showPages<$pages && $page + $offset < $pages) $endOmit = '...';
  55. }
  56. ?>
  57. <!-- 动态生成分页条 跳转地址 当前页码的高亮显示 -->
  58. <p>
  59. <!-- 首页 上一页 下一页 尾页 -->
  60. <!-- 获取上一页 -->
  61. <?php $prev = $page-1; if($page == 1) $prev = 1; if($page != 1):?>
  62. <a href="/page/1">首页</a>
  63. <a href="/page/<?=$prev?>">上一页</a>
  64. <?endif?>
  65. <?php if(isset($startOmit)):?>
  66. <a href="javascript:;"><?=$startOmit?></a><?endif?>
  67. <?php
  68. for ($i=$startPage; $i <=$endPage ; $i++) :
  69. //生成动态的跳转地址 a href 属性 $jump
  70. $jump = sprintf('/page/%d',$i);
  71. $active = ($i==$page) ? 'active' : null;
  72. ?>
  73. <a class="<?=$active?>" href="<?=$jump?>"><?=$i?></a>
  74. <? endfor;?>
  75. <?php if(isset($endOmit)):?>
  76. <a href="javascript:;"><?=$endOmit?></a><?endif?>
  77. <!-- 下一页 -->
  78. <?php $next = $page+1; if($next == $pages) $next=$page; if($page != $pages) :?>
  79. <a href="/page/<?=$next?>">下一页</a>
  80. <a href="/page/<?=$pages?>">尾页</a>
  81. <?endif?>
  82. </p>
  83. </body>
  84. </html>

②Controller 中间控制器类文件

三.Public 主页文件

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post