博客列表 >12月10号:周作业实现HTML页面数据动态填充

12月10号:周作业实现HTML页面数据动态填充

Rambo-Yang
Rambo-Yang原创
2019年12月15日 14:49:531107浏览

文件结构:

数据库article表

Db.php 数据库配置信息 PDO连接

  1. namespace Model;
  2. class Db
  3. {
  4. private $dbConfig = [
  5. 'type' => 'mysql',
  6. 'host' => '127.0.0.1',
  7. 'username' => 'root',
  8. 'password' => 'root',
  9. 'dbname' => 'a_io',
  10. ];
  11. public static $pdo =null;
  12. //私有化构造方法,禁止外部调用
  13. private function __construct()
  14. {
  15. $this->connect();
  16. }
  17. private function connect(){
  18. try {
  19. $dsn = "{$this->dbConfig['type']}:host={$this->dbConfig['host']};dbname={$this->dbConfig['dbname']}";
  20. self::$pdo = new \PDO($dsn,$this->dbConfig['username'],$this->dbConfig['password']);
  21. }catch (\PDOException $e){
  22. die('数据库连接失败:' . $e->getMessage());
  23. }
  24. }
  25. //单例模式
  26. public static function connection()
  27. {
  28. if (is_null(self::$pdo)){
  29. new self();
  30. }
  31. return self::$pdo;
  32. }
  33. //私有化克隆方法
  34. private function __clone()
  35. {
  36. }
  37. }

Model.php 模型

  1. namespace Model;
  2. require 'Db.php';
  3. class Model
  4. {
  5. public $pdo = null;
  6. //构造方法连接数据库
  7. public function __construct()
  8. {
  9. $this->pdo = Db::connection();
  10. }
  11. public function getLimit($table,$limit = 1,$where = '')
  12. {
  13. if (!empty($where)){
  14. $where =' WHERE ' . $where ;
  15. }
  16. $sql = "SELECT * FROM {$table} {$where} LIMIT {$limit}";
  17. $stmt = $this->pdo->prepare($sql);
  18. $stmt->execute();
  19. // $stmt->debugDumpParams();
  20. return $stmt->fetchAll(\PDO::FETCH_ASSOC);
  21. }
  22. }

View.php 视图

  1. namespace View;
  2. class View
  3. {
  4. public function getLimitData($data)
  5. {
  6. return $data;
  7. }
  8. }

Controller.php 控制器

  1. namespace Controller;
  2. require dirname(__DIR__) .'/common/autoload.php';
  3. use Model\Model;
  4. use View\View;
  5. class Container
  6. {
  7. public $instance = [];
  8. //存进去,绑定类实例方法
  9. public function bind($alias,\Closure $process)
  10. {
  11. $this->instance[$alias] = $process;
  12. }
  13. //取出来,执行实例化过程
  14. public function make($alias,$params = [])
  15. {
  16. return call_user_func_array($this->instance[$alias],$params);
  17. }
  18. }
  19. $container = new Container();
  20. $container->bind('model',function (){return new Model();});
  21. $container->bind('view',function (){return new View();});
  22. class Facade
  23. {
  24. //创建容器数据,接收实例化后的类
  25. protected static $container = null;
  26. //存储数据
  27. protected static $data = [];
  28. public static function initialize($container)
  29. {
  30. static::$container = $container;
  31. }
  32. //静态化模型方法
  33. public static function getLimit($table,$limit = 1,$where = '')
  34. {
  35. static::$data = static::$container->make('model')->getLimit($table,$limit,$where);
  36. }
  37. //静态化视图方法
  38. public static function getLimitData()
  39. {
  40. return static::$container->make('view')->getLimitData(static::$data);
  41. }
  42. }
  43. class Controller
  44. {
  45. //初始化门面
  46. public function __construct(Container $container)
  47. {
  48. Facade::initialize($container);
  49. }
  50. public function indexLimit($table,$limit = 1 ,$where = '')
  51. {
  52. //获取数据
  53. Facade::getLimit($table,$limit,$where);
  54. //渲染模板
  55. return Facade::getLimitData();
  56. }
  57. }

autoload.php 自动加载

  1. //自动加载
  2. spl_autoload_register(function ($className){
  3. $path = str_replace('\\','/',$className);
  4. require dirname(__DIR__) . '/' . $path . '.php';
  5. });

前端页面

head.php 公共头部

  1. <!--公共顶部导航区-->
  2. <header>
  3. <a href="">网站首页</a>
  4. <a href="">专题</a>
  5. <a href="">网站导航</a>
  6. <a href="">二手商品</a>
  7. <a href="">讨论区</a>
  8. <span><a href=""><i class="iconfont icon-huiyuan2"></i>登陆</a><a href="">免费注册</a></span>
  9. </header>
  10. <style>
  11. img { max-width: 100%;}
  12. </style>
  1. <footer>
  2. <div>
  3. <a href="">简介</a>
  4. <a href="">联系我们</a>
  5. <a href="">招聘信息</a>
  6. <a href="">友情链接</a>
  7. <a href="">用户服务协议</a>
  8. <a href="">隐私权声明</a>
  9. <a href="">法律投诉声明</a>
  10. </div>
  11. <div><span>LOGO</span></div>
  12. <div>
  13. <p>2019 fengniao.com. All rights reserved . 安徽闹着玩***(无聊网)版权所有</p>
  14. <p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
  15. <p>违法和不良信息举报电话: 0551-1234567 举报邮箱: admin@baidu.com</p>
  16. </div>
  17. <div>
  18. <p>关注公众号</p>
  19. <img src="static/images/erwei-code.png" alt="">
  20. </div>
  21. </footer>

index.php 首页

  1. <?php
  2. require 'Controller\Controller.php';
  3. //文章
  4. $limit1 = $controller -> indexLimit('article',1);
  5. $limit9 = $controller -> indexLimit('article','1,9');
  6. //图片
  7. $photo = $controller -> indexLimit('photo',2);
  8. $photo1 = $controller -> indexLimit('photo','2,2');
  9. $photo2 = $controller -> indexLimit('photo','4,2');
  10. $photo3 = $controller -> indexLimit('photo','6,2');
  11. $photo4 = $controller -> indexLimit('photo','8,2');
  12. $photo5 = $controller -> indexLimit('photo','10,2');
  13. //汽车
  14. $shop = $controller -> indexLimit('shop',4);
  15. $shop1 = $controller -> indexLimit('shop','4,4');
  16. ?>
  17. <!DOCTYPE html>
  18. <html lang="en">
  19. <head>
  20. <meta charset="UTF-8">
  21. <title>首页</title>
  22. <!-- <link rel="stylesheet" href="static/css/reset.css">-->
  23. <link rel="stylesheet" href="static/font/iconfont.css">
  24. <link rel="stylesheet" href="static/css/index.css">
  25. </head>
  26. <body>
  27. <?php include 'common/head.php';?>
  28. <!--logo+搜索框+快捷入口区-->
  29. <div class="logo">
  30. <img src="static/images/logo.png" alt="">
  31. <label>
  32. <input type="search">
  33. <a href="" class="iconfont icon-jinduchaxun"></a>
  34. </label>
  35. <span>
  36. <a href="" class="iconfont icon-huiyuan1"></a>
  37. <a href="" class="iconfont icon-danmu"></a>
  38. <a href="" class="iconfont icon-duoxuankuang"></a>
  39. <a href="" class="iconfont icon-jishufuwu"></a>
  40. <a href="" class="iconfont icon-peiwangyindao"></a>
  41. <a href="" class="iconfont icon-wenjianjia"></a>
  42. <a href="" class="iconfont icon-huiyuan1"></a>
  43. </span>
  44. </div>
  45. <!--主导航区-->
  46. <nav>
  47. <div>
  48. <span class="iconfont icon-gongdan"></span>
  49. <span>资讯 <br> 看学</span>
  50. <a href="">器材</a>
  51. <a href="">大师</a>
  52. <a href="">学院</a>
  53. <a href="">影赛</a>
  54. <a href="">器材</a>
  55. <a href="">大师</a>
  56. <a href="">学院</a>
  57. <a href="">影赛</a>
  58. </div>
  59. <div>
  60. <span class="iconfont icon-renwujincheng"></span>
  61. <span>资讯 <br> 看学</span>
  62. <a href="">器材</a>
  63. <a href="">大师</a>
  64. <a href="">学院</a>
  65. <a href="">影赛</a>
  66. <a href="">器材</a>
  67. <a href="">大师</a>
  68. <a href="">学院</a>
  69. <a href="">影赛</a>
  70. </div>
  71. <div>
  72. <span class="iconfont icon-gongdan"></span>
  73. <span>资讯 <br> 看学</span>
  74. <a href="">器材</a>
  75. <a href="">大师</a>
  76. <a href="">学院</a>
  77. <a href="">影赛</a>
  78. <a href="">器材</a>
  79. <a href="">大师</a>
  80. <a href="">学院</a>
  81. <a href="">影赛</a>
  82. </div>
  83. <div>
  84. <span class="iconfont icon-DOC"></span>
  85. <span>资讯 <br> 看学</span>
  86. <a href="">器材</a>
  87. <a href="">大师</a>
  88. <a href="">学院</a>
  89. <a href="">影赛</a>
  90. <a href="">器材</a>
  91. <a href="">大师</a>
  92. <a href="">学院</a>
  93. <a href="">影赛</a>
  94. </div>
  95. </nav>
  96. <!--轮播图-->
  97. <div class="slider">
  98. <img src="static/images/1.jpg" alt="">
  99. <img src="static/images/banner-right.jpg" alt="">
  100. </div>
  101. <!--新闻资讯区-->
  102. <div class="news">
  103. <div class="title">
  104. <a>新闻资讯</a>
  105. <a href="">更多</a>
  106. </div>
  107. <div class="content">
  108. <div class="pic">
  109. <a href=""><img src="static/images/news.jpg" alt="" class="first-img"></a>
  110. <a href=""><img src="static/images/n-2.jpg" alt=""></a>
  111. <a href=""><img src="static/images/n-3.jpg" alt=""></a>
  112. <a href="">三星Note10/10+发布 <br> 搭载挖孔前摄</a>
  113. <a href="">小米公布6400万 <br> 和1亿像素手机信息</a>
  114. </div>
  115. <div class="list">
  116. <?php foreach($limit1 as $row) :?>
  117. <a href="article.php?id=<?php echo $row['id'] ?>"><?php echo mb_substr($row['title'],0,15) ?></a>
  118. <?php endforeach;?>
  119. <ul> <?php foreach($limit9 as $row) :?>
  120. <li><span>[新闻]</span><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  121. <?php endforeach;?>
  122. </ul>
  123. </div>
  124. <div class="list">
  125. <?php foreach ($limit1 as $row) : ?>
  126. <a href="article.php?id=<?php echo $row['id']; ?>"><?php echo mb_substr($row['title'],0,15) ?></a>
  127. <?php endforeach; ?>
  128. <ul>
  129. <?php foreach($limit9 as $row) :?>
  130. <li><span>[新闻]</span><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  131. <?php endforeach;?>
  132. </ul>
  133. </div>
  134. </div>
  135. </div>
  136. <!--图片专区-->
  137. <div class="title">
  138. <span>图片专区</span>
  139. </div>
  140. <div class="picture">
  141. <div>
  142. <div>
  143. <a href="">自然风光</a>
  144. <span>纵观摄影艺术</span>
  145. </div>
  146. <?php foreach ($photo as $item) : ?>
  147. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  148. <?php endforeach; ?>
  149. <?php foreach ($photo as $item) : ?>
  150. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  151. <?php endforeach; ?>
  152. <?php foreach ($photo1 as $item) : ?>
  153. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  154. <?php endforeach; ?>
  155. <?php foreach ($photo1 as $item) : ?>
  156. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  157. <?php endforeach; ?>
  158. </div>
  159. <div>
  160. <div>
  161. <a href="">自然风光</a>
  162. <span>纵观摄影艺术</span>
  163. </div>
  164. <?php foreach ($photo2 as $item) : ?>
  165. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  166. <?php endforeach; ?>
  167. <?php foreach ($photo2 as $item) : ?>
  168. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  169. <?php endforeach; ?>
  170. <?php foreach ($photo3 as $item) : ?>
  171. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  172. <?php endforeach; ?>
  173. <?php foreach ($photo3 as $item) : ?>
  174. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  175. <?php endforeach; ?>
  176. </div>
  177. <div>
  178. <div>
  179. <a href="">自然风光</a>
  180. <span>纵观摄影艺术</span>
  181. </div>
  182. <?php foreach ($photo4 as $item) : ?>
  183. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  184. <?php endforeach; ?>
  185. <?php foreach ($photo4 as $item) : ?>
  186. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  187. <?php endforeach; ?>
  188. <?php foreach ($photo5 as $item) : ?>
  189. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="162" height="122"></a>
  190. <?php endforeach; ?>
  191. <?php foreach ($photo5 as $item) : ?>
  192. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  193. <?php endforeach; ?>
  194. </div>
  195. </div>
  196. <!--二手交易专区-->
  197. <div class="title">
  198. <span>汽车***</span>
  199. </div>
  200. <div class="second-hand">
  201. <div>
  202. <a href="">抢好货</a>
  203. <span>0低价, 便捷,安全,快速</span>
  204. </div>
  205. <div>
  206. <span>热门分类</span>
  207. <a href="">国产新车</a>
  208. <a href="">海外车讯</a>
  209. <a href="">新车谍照</a>
  210. <a href="">***新车</a>
  211. <a href="">新车盘点</a>
  212. </div>
  213. <?php foreach ($shop as $item) : ?>
  214. <a href="shop.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="176" height="120"></a>
  215. <?php endforeach; ?>
  216. <?php foreach ($shop as $item) : ?>
  217. <div class="detail">
  218. <a href="shop.php?id=<?php echo $item['id'] ?>"><?php echo $item['title'] ?></a>
  219. <div>
  220. <a href="shop.php?id=<?php echo $item['id'] ?>">
  221. <span>¥ <?php echo $item['price'] ?></span>
  222. <span>新车</span>
  223. </a>
  224. </div>
  225. </div>
  226. <?php endforeach; ?>
  227. <?php foreach ($shop1 as $item) : ?>
  228. <a href="shop.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="176" height="120"></a>
  229. <?php endforeach; ?>
  230. <?php foreach ($shop1 as $item) : ?>
  231. <div class="detail">
  232. <a href="shop.php?id=<?php echo $item['id'] ?>"><?php echo $item['title'] ?></a>
  233. <div>
  234. <a href="shop.php?id=<?php echo $item['id'] ?>">
  235. <span>¥ <?php echo $item['price'] ?></span>
  236. <span>新车</span>
  237. </a>
  238. </div>
  239. </div>
  240. <?php endforeach; ?>
  241. <div>
  242. <a href=""><img src="static/images/ad/1.png" alt="" width="180" height="112"></a>
  243. <a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
  244. <a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
  245. <a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
  246. <a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
  247. <a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
  248. </div>
  249. </div>
  250. <!--合作网站-->
  251. <div class="title" style="background:#fff">
  252. <span>合作网站</span>
  253. </div>
  254. <div class="my-links">
  255. <a href="https://www.php.cn">php中文网</a>
  256. <a href="https://www.html.cn">html中文网</a>
  257. <a href="https://www.py.cn">python中文网</a>
  258. <a href="https://www.php.cn">php中文网</a>
  259. <a href="https://www.html.cn">html中文网</a>
  260. <a href="https://www.py.cn">python中文网</a>
  261. <a href="https://www.php.cn">php中文网</a>
  262. <a href="https://www.html.cn">html中文网</a>
  263. <a href="https://www.py.cn">python中文网</a>
  264. <a href="https://www.php.cn">php中文网</a>
  265. <a href="https://www.html.cn">html中文网</a>
  266. <a href="https://www.py.cn">python中文网</a>
  267. <a href="https://www.py.cn">python中文网</a>
  268. <a href="https://www.php.cn">php中文网</a>
  269. <a href="https://www.html.cn">html中文网</a>
  270. <a href="https://www.py.cn">python中文网</a>
  271. <a href="https://www.php.cn">php中文网</a>
  272. <a href="https://www.html.cn">html中文网</a>
  273. <a href="https://www.py.cn">python中文网</a>
  274. <a href="https://www.php.cn">php中文网</a>
  275. <a href="https://www.html.cn">html中文网</a>
  276. <a href="https://www.py.cn">python中文网</a>
  277. <a href="https://www.php.cn">php中文网</a>
  278. <a href="https://www.html.cn">html中文网</a>
  279. <a href="https://www.py.cn">python中文网</a>
  280. <a href="https://www.py.cn">python中文网</a>
  281. </div>
  282. <!--页底部-->
  283. <?php include 'common/footer.php';?>
  284. </body>
  285. </html>

arclist-list.php 新闻列表页

  1. <?php
  2. require 'Controller\Controller.php';
  3. $id = isset($_GET['id']) ? $_GET['id'] : 0 ;
  4. if ($id == 0){
  5. echo "<script>alert('ID不存在!'); location.assign('index.php');</script>";
  6. }
  7. $list = $controller->indexLimit('article', 10 ,"listid=$id" );
  8. $limit6= $controller -> indexLimit('article',6);
  9. $limit6_2 = $controller -> indexLimit('article','6,6');
  10. $limit4= $controller -> indexLimit('article',4);
  11. $limit4_2 = $controller -> indexLimit('photo',4);
  12. function tranTime($time)
  13. {
  14. $rtime = date("m-d H:i",$time);
  15. $htime = date("H:i",$time);
  16. $time = time() - $time;
  17. if ($time < 60)
  18. {
  19. $str = '刚刚';
  20. }
  21. elseif ($time < 60 * 60)
  22. {
  23. $min = floor($time/60);
  24. $str = $min.'分钟前';
  25. }
  26. elseif ($time < 60 * 60 * 24)
  27. {
  28. $h = floor($time/(60*60));
  29. $str = $h.'小时前 ';
  30. }
  31. elseif ($time < 60 * 60 * 24 * 3)
  32. {
  33. $d = floor($time/(60*60*24));
  34. if($d==1)
  35. $str = '昨天 '.$rtime;
  36. else
  37. $str = '前天 '.$rtime;
  38. }
  39. else
  40. {
  41. $str = $rtime;
  42. }
  43. return $str;
  44. }
  45. ?>
  46. <!DOCTYPE html>
  47. <html lang="en">
  48. <head>
  49. <meta charset="UTF-8">
  50. <title>文章详情页面</title>
  51. <link rel="stylesheet" href="static/font/iconfont.css">
  52. <link rel="stylesheet" href="static/css/article-list.css">
  53. </head>
  54. <body>
  55. <!--公共顶部导航区-->
  56. <?php include 'common/head.php';?>
  57. <div class="main">
  58. <div class="top">
  59. <img src="static/images/ar-logo.png" alt="">
  60. <a href="">财经</a>><span>正文</span>
  61. <label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
  62. </div>
  63. <!-- 列表-->
  64. <article>
  65. <div>
  66. <a href="">头条</a>
  67. <a href="">热文</a>
  68. <a href="">直播</a>
  69. <a href="" id="active">新闻</a>
  70. <a href="">政策地图</a>
  71. <a href="">相对论</a>
  72. <a href="">人物</a>
  73. <a href="">行情</a>
  74. <a href="">投研</a>
  75. <a href="">技术</a>
  76. <a href="">百科</a>
  77. </div>
  78. <?php foreach ($list as $item) : ?>
  79. <div class="list1">
  80. <a href="article.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="272"></a>
  81. <div>
  82. <a href="article.php?id=<?php echo $item['id'] ?>"><?php echo $item['title'] ?></a>
  83. <span><?php echo $item['title'] ?></span>
  84. </div>
  85. <a href="article.php?id=<?php echo $item['id'] ?>">区块链头条 · <?php echo tranTime($item['pubdate']) ?></a>
  86. <span><i class="iconfont icon-icon_yulan"></i><?php echo $item['read'] ?></span>
  87. </div>
  88. <?php endforeach; ?>
  89. </article>
  90. <!-- 右侧列表-->
  91. <div class="list1">
  92. <h3>网页评论</h3>
  93. <ul>
  94. <?php foreach($limit6 as $row) :?>
  95. <li><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  96. <?php endforeach;?>
  97. </ul>
  98. </div>
  99. <div class="list2">
  100. <h3>网页评论</h3>
  101. <ul>
  102. <?php foreach($limit6_2 as $row) :?>
  103. <li><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  104. <?php endforeach;?>
  105. </ul>
  106. </div>
  107. <div class="recommend">
  108. <h3>推荐阅读</h3>
  109. <?php foreach ($limit4 as $item) : ?>
  110. <a href="article.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="195" height="130"></a>
  111. <?php endforeach; ?>
  112. <?php foreach ($limit4 as $item) : ?>
  113. <a href="article.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  114. <?php endforeach; ?>
  115. <?php foreach ($limit4_2 as $item) : ?>
  116. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="195" height="130"></a>
  117. <?php endforeach; ?>
  118. <?php foreach ($limit4_2 as $item) : ?>
  119. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  120. <?php endforeach; ?>
  121. </div>
  122. </div>
  123. <!--页底部-->
  124. <?php include 'common/footer.php';?>
  125. </body>
  126. </html>

article.php 文章详情页

  1. <?php
  2. require 'Controller\Controller.php';
  3. $id = isset($_GET['id']) ? $_GET['id'] : 0 ;
  4. if ($id == 0){
  5. echo "<script>alert('ID不存在!'); location.assign('index.php');</script>";
  6. }
  7. $article = $controller->indexLimit('article', 1 ,"id=$id" );
  8. $article = $article[0];
  9. $limit6= $controller -> indexLimit('article',6);
  10. $limit6_2 = $controller -> indexLimit('article','6,6');
  11. $limit4= $controller -> indexLimit('article',4);
  12. $limit4_2 = $controller -> indexLimit('photo',4);
  13. ?>
  14. <!DOCTYPE html>
  15. <html lang="en">
  16. <head>
  17. <meta charset="UTF-8">
  18. <title><?php echo $article['title'] ?></title>
  19. <link rel="stylesheet" href="static/font/iconfont.css">
  20. <link rel="stylesheet" href="static/css/article.css">
  21. </head>
  22. <body>
  23. <!--公共顶部导航区-->
  24. <?php include 'common/head.php'; ?>
  25. <div class="main">
  26. <div class="top">
  27. <img src="static/images/ar-logo.png" alt="">
  28. <a href="">财经</a>&gt;<span>正文</span>
  29. <label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
  30. </div>
  31. <!-- 正文-->
  32. <article>
  33. <h1><?php echo $article['title'] ?></h1>
  34. <div>
  35. <span>发布时间:<?php echo date('Y-m-d',$article['pubdate']) ?></span>
  36. <span>来源:<?php echo $article['source'] ?></span>
  37. <span>阅读量:<?php echo $article['read'] ?></span>
  38. <span>评论数:1545</span>
  39. </div>
  40. <div>
  41. <?php echo $article['body'] ?>
  42. </div>
  43. </article>
  44. <!-- 右侧列表-->
  45. <div class="list1">
  46. <h3>网页评论</h3>
  47. <ul>
  48. <?php foreach($limit6 as $row) :?>
  49. <li><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  50. <?php endforeach;?>
  51. </ul>
  52. </div>
  53. <div class="list2">
  54. <h3>网页评论</h3>
  55. <ul>
  56. <?php foreach($limit6_2 as $row) :?>
  57. <li><a href="article.php?id=<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></li>
  58. <?php endforeach;?>
  59. </ul>
  60. </div>
  61. <div class="ding">
  62. <span></span>
  63. <span></span>
  64. </div>
  65. <div class="comment">
  66. <h3>网页评论</h3>
  67. <img src="static/images/user.png" alt="" width="60">
  68. <textarea name="" id="" cols="30" rows="10"></textarea>
  69. <button>发表评论</button>
  70. </div>
  71. <div class="recommend">
  72. <h3>推荐阅读</h3>
  73. <?php foreach ($limit4 as $item) : ?>
  74. <a href="article.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="195" height="130"></a>
  75. <?php endforeach; ?>
  76. <?php foreach ($limit4 as $item) : ?>
  77. <a href="article.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  78. <?php endforeach; ?>
  79. <?php foreach ($limit4_2 as $item) : ?>
  80. <a href="photo.php?id=<?php echo $item['id'] ?>"><img src="<?php echo $item['litpic'] ?>" alt="" width="195" height="130"></a>
  81. <?php endforeach; ?>
  82. <?php foreach ($limit4_2 as $item) : ?>
  83. <a href="photo.php?id=<?php echo $item['id'] ?>"><span><?php echo $item['title'] ?></span></a>
  84. <?php endforeach; ?>
  85. </div>
  86. </div>
  87. <!--页底部-->
  88. <?php include 'common/footer.php';?>
  89. </body>
  90. </html>
  • 图片和商品页面原理一样就不重复提交了

首页

新闻列表页

内容详情页

总结

  • 通过<a href='article.php?id=1'>点击传值</a> 传值,$_GET['id']接收。
  • 基本掌握简单的MVC流程,虽然写的时候还是不断的出现各种错误,现在可以找到问题并解决了。
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议