博客列表 >12月15日_PHP大作业

12月15日_PHP大作业

fkkf467
fkkf467原创
2019年12月17日 18:14:351044浏览

1. 项目文件结构

2. 数据表



3. 代码

Db.php

  1. <?php
  2. // 定义命名空间
  3. namespace project\model;
  4. // 引入类的别名
  5. use PDO;
  6. use PDOException;
  7. // 用于连接数据库
  8. class Db
  9. {
  10. // 连接属性
  11. public static $pdo = null;
  12. // 构造方法私有化
  13. // 在构造方法中实现连接数据库
  14. private function __construct()
  15. {
  16. try {
  17. self::$pdo = new PDO('mysql:host=localhost;dbname=php','root','root');
  18. }catch (PDOException $e){
  19. die('数据库连接失败,错误信息为:' . $e->getMessage());
  20. }
  21. }
  22. public static function getInstance()
  23. {
  24. if (is_null(self::$pdo)){
  25. new self();
  26. }
  27. return self::$pdo;
  28. }
  29. // 克隆方法私有化
  30. private function __clone()
  31. {
  32. }
  33. }

Model.php

  1. <?php
  2. // 定义命名空间
  3. namespace project\model;
  4. // 引入Db类文件
  5. //require 'Db.php';
  6. use PDO;
  7. // 公共模型类
  8. class Model
  9. {
  10. // 连接属性
  11. public $pdo = null;
  12. // 获取当前类名
  13. public $className = self::class;
  14. // 构造方法实现自动连接数据库
  15. public function __construct()
  16. {
  17. $this->pdo = Db::getInstance();
  18. }
  19. // 查询多条记录
  20. public function select($table, $fields = '*', $where = '', $order = '', $limit = '')
  21. {
  22. // 创建SQL语句
  23. $sql = 'SELECT ';
  24. if (is_array($fields)) {
  25. foreach ($fields as $field) {
  26. $sql .= $field . ', ';
  27. }
  28. } else {
  29. $sql .= $fields;
  30. }
  31. $sql = rtrim(trim($sql), ',');
  32. $sql .= ' FROM ' . $table;
  33. // 查询条件
  34. if (!empty($where)) {
  35. $sql .= ' WHERE ' . $where;
  36. }
  37. // 排序方式
  38. if (!empty($order)) {
  39. $sql .= ' ORDER BY ' . $order;
  40. }
  41. // 分页
  42. if (!empty($limit)) {
  43. $sql .= ' LIMIT ' . $limit;
  44. }
  45. $sql .= ';';
  46. // 创建PDO预处理对象
  47. $stmt = $this->pdo->prepare($sql);
  48. // 执行查询操作
  49. if ($stmt->execute()) {
  50. if ($stmt->rowCount() > 0) {
  51. $stmt->setFetchMode(PDO::FETCH_CLASS, $this->className);
  52. return $stmt->fetchAll();
  53. }
  54. }
  55. return '查询失败';
  56. }
  57. // 查询单条记录
  58. public function find($table, $fields, $where = '')
  59. {
  60. $sql = 'SELECT ';
  61. if (is_array($fields)) {
  62. foreach ($fields as $field) {
  63. $sql .= $field . ', ';
  64. }
  65. } else {
  66. $sql .= $fields;
  67. }
  68. $sql = rtrim(trim($sql), ',');
  69. $sql .= ' FROM ' . $table;
  70. if (!empty($where)) {
  71. $sql .= ' WHERE ' . $where;
  72. }
  73. $sql .= ' LIMIT 1;';
  74. $stmt = $this->pdo->prepare($sql);
  75. if ($stmt->execute()) {
  76. if ($stmt->rowCount() > 0) {
  77. $stmt->setFetchMode(PDO::FETCH_CLASS, $this->className);
  78. return $stmt->fetch();
  79. }
  80. }
  81. return '查询失败';
  82. }
  83. public function __destruct()
  84. {
  85. $this->pdo = null;
  86. }
  87. }

Article.php

  1. <?php
  2. namespace project\model;
  3. class Article extends Model
  4. {
  5. public $addtime;
  6. public $className = self::class;
  7. public function setData()
  8. {
  9. $t = time();
  10. if ($t - $this->addtime < 60) {
  11. return ($t - $this->addtime) . '秒'; // 秒
  12. } else if ($t - $this->addtime < 60 * 60) {
  13. return round((($t - $this->addtime) / 60)-0.5) . '分钟'; // 分
  14. } else if ($t - $this->addtime < 24 * 60 * 60) {
  15. return round((($t - $this->addtime) / (60 * 60))-0.5) . '小时'; // 时
  16. } else if ($t - $this->addtime < 7 * 24 * 60 * 60) {
  17. return round((($t - $this->addtime) / (24 * 60 * 60))-0.5) . '天'; // 天
  18. } else if ($t - $this->addtime < 30 * 7 * 24 * 60 * 60) {
  19. return round((($t - $this->addtime) / (7 * 24 * 60 * 60))-0.5) . '星期'; // 周
  20. } else if ($t - $this->addtime < 365 * 30 * 7 * 24 * 60 * 60) {
  21. return round((($t - $this->addtime) / (30 * 7 * 24 * 60 * 60))-0.5) . '月'; // 月
  22. } else {
  23. return round((($t - $this->addtime) / (365 * 30 * 7 * 24 * 60 * 60))-0.5) . '年'; // 年
  24. }
  25. }
  26. }

Good.php

  1. <?php
  2. namespace project\model;
  3. class Good extends Model
  4. {
  5. public $className = self::class;
  6. }

Picture.php

  1. <?php
  2. namespace project\model;
  3. class Picture extends Model
  4. {
  5. public $className = self::class;
  6. }

View.php

  1. <?php
  2. namespace project\view;
  3. // 视图类
  4. class View
  5. {
  6. // 获取数据,并将数据返回
  7. public function data($data)
  8. {
  9. return $data;
  10. }
  11. }

Container.php

  1. <?php
  2. namespace project\controller;
  3. use Closure;
  4. // 服务容器类
  5. class Container
  6. {
  7. // 容器属性:用来保存创建对象的方法
  8. protected $instance = [];
  9. // 将类的实例化过程绑定到容器中
  10. public function bind($alias, Closure $process)
  11. {
  12. $this->instance[$alias] = $process;
  13. }
  14. // 执行容器中的实例化方法
  15. public function make($alias,$params=[])
  16. {
  17. return call_user_func_array($this->instance[$alias],$params);
  18. }
  19. }

Facade.php

  1. <?php
  2. namespace project\controller;
  3. // 门面类
  4. class Facade
  5. {
  6. protected static $container = null;
  7. protected static $data = [];
  8. // 用服务容器将静态属性初始化
  9. public static function initialize(Container $container)
  10. {
  11. static::$container = $container;
  12. }
  13. // 用静态代理的方式将模型类中的 select() 方法静态化
  14. public static function select($model, $table, $fields = '*', $where = '', $order = '', $limit = '')
  15. {
  16. static::$data = static::$container->make($model)->select($table, $fields, $where, $order, $limit);
  17. }
  18. // 用静态代理的方式将模型类中的 find() 静态化
  19. public static function find($model, $table, $fields, $where = '')
  20. {
  21. static::$data = static::$container->make($model)->find($table, $fields, $where);
  22. }
  23. // 用静态代理的方式将视图类中的 data() 静态化
  24. public static function data($view)
  25. {
  26. return static::$container->make($view)->data(static::$data);
  27. }
  28. }

Controller.php

  1. <?php
  2. namespace project\controller;
  3. // 控制器类
  4. class Controller
  5. {
  6. // 使用构造方法,自动调用Facade类里面的初始化方法
  7. public function __construct(Container $container)
  8. {
  9. Facade::initialize($container);
  10. }
  11. // 查询多条数据
  12. public function select($model, $view, $table, $fields = '*', $where = '', $order = '', $limit = '')
  13. {
  14. Facade::select($model, $table, $fields, $where, $order, $limit);
  15. return Facade::data($view);
  16. }
  17. // 查询单条数据
  18. public function find($model, $view, $table, $fields, $where = '')
  19. {
  20. Facade::find($model,$table,$fields,$where);
  21. return Facade::data($view);
  22. }
  23. }

common.php

  1. <?php
  2. namespace project;
  3. use project\controller\Controller;
  4. use project\controller\Container;
  5. use project\model\Article;
  6. use project\model\Good;
  7. use project\model\Picture;
  8. use project\view\View;
  9. require __DIR__ . '/autoload.php';
  10. $container = new Container();
  11. $container->bind('article', function () {
  12. return new Article();
  13. });
  14. $container->bind('picture',function (){
  15. return new Picture();
  16. });
  17. $container->bind('good',function (){
  18. return new Good();
  19. });
  20. $container->bind('view', function () {
  21. return new View();
  22. });
  23. $controller = new Controller($container);

header.php

  1. <!--公共顶部导航区-->
  2. <header>
  3. <a href="index.php">网站首页</a>
  4. <a href="article_list.php">文章专题</a>
  5. <a href="image.php">图片站</a>
  6. <a href="shop.php">二手商品</a>
  7. <a href="">讨论区</a>
  8. <span><a href=""><i class="iconfont icon-huiyuan2"></i>登陆</a><a href="">免费注册</a></span>
  9. </header>

footrt.php

  1. <!--页底部-->
  2. <footer>
  3. <div>
  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. <a href="">法律投诉声明</a>
  11. </div>
  12. <div><span>LOGO</span></div>
  13. <div>
  14. <p>2019 fengniao.com. All rights reserved . 安徽闹着玩有限公司(无聊网)版权所有</p>
  15. <p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
  16. <p>违法和不良信息举报电话: 0551-1234567 举报邮箱: admin@baidu.com</p>
  17. </div>
  18. <div>
  19. <p>关注公众号</p>
  20. <img src="static/images/erwei-code.png" alt="">
  21. </div>
  22. </footer>
  23. </body>
  24. </html>

autoload.php

  1. <?php
  2. namespace project_test;
  3. // 类的自动加载
  4. spl_autoload_register(function ($className){
  5. $path = str_replace('\\', '/', $className);
  6. require dirname(__DIR__) . DIRECTORY_SEPARATOR . $path . '.php';
  7. });

index.php

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

article_list.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $articles = $controller->select('article', 'view', 'articles','*','','',8);
  4. $reads = $controller->select('article', 'view', 'articles', '*', '', 'readership DESC', 6);
  5. $comments = $controller->select('article', 'view', 'articles', '*', '', 'comment_number DESC', 6);
  6. $recommends_img = [];
  7. $recommends_title = [];
  8. $recommends_id = [];
  9. foreach ($articles as $article) {
  10. if ($article->recommend == 1) {
  11. $recommends_img[] = $article->image;
  12. $recommends_title[] = $article->title;
  13. $recommends_id[] = $article->article_id;
  14. }
  15. }
  16. ?>
  17. <!DOCTYPE html>
  18. <html lang="en">
  19. <head>
  20. <meta charset="UTF-8">
  21. <title>文章列表页</title>
  22. <link rel="stylesheet" href="static/font/iconfont.css">
  23. <link rel="stylesheet" href="static/css/article-list.css">
  24. </head>
  25. <body>
  26. <?php
  27. require __DIR__ . '/header.php';
  28. ?>
  29. <div class="main">
  30. <div class="top">
  31. <img src="static/images/ar-logo.png" alt="">
  32. <label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
  33. </div>
  34. <!-- 列表-->
  35. <article>
  36. <div>
  37. <a href="">头条</a>
  38. <a href="">热文</a>
  39. <a href="">直播</a>
  40. <a href="" id="active">新闻</a>
  41. <a href="">政策地图</a>
  42. <a href="">相对论</a>
  43. <a href="">人物</a>
  44. <a href="">行情</a>
  45. <a href="">投研</a>
  46. <a href="">技术</a>
  47. <a href="">百科</a>
  48. </div>
  49. <?php
  50. foreach ($articles as $article) {
  51. echo '<div class="list1">';
  52. echo '<a href="article.php?article_id=' . $article->article_id . '"><img src="static/images/' . $article->image . '" alt="" width="272" height="180"></a>';
  53. echo '<div>';
  54. echo '<a href="article.php?article_id=' . $article->article_id . '">' . $article->title . '</a>';
  55. echo '<span>' . mb_substr($article->content, 0, 50, "utf-8") . '...</span>';
  56. echo '</div>';
  57. echo '<a href="">' . $article->cate . ' · ' . $article->setData() . '前</a>';
  58. echo '<span><i class="iconfont icon-icon_yulan"></i>' . $article->readership . '</span>';
  59. echo '</div>';
  60. }
  61. ?>
  62. </article>
  63. <!-- 右侧列表-->
  64. <div class="list1">
  65. <h3>阅读量排行榜</h3>
  66. <ul>
  67. <?php
  68. foreach ($reads as $read) {
  69. echo '<li><a href="article.php?article_id=' . $read->article_id . '">' . $read->title . '</a></li>';
  70. }
  71. ?>
  72. </ul>
  73. </div>
  74. <div class="list2">
  75. <h3>评论数排行榜</h3>
  76. <ul>
  77. <?php
  78. foreach ($comments as $comment) {
  79. echo '<li><a href="article.php?article_id=' . $comment->article_id . '">' . $comment->title . '</a></li>';
  80. }
  81. ?>
  82. </ul>
  83. </div>
  84. <div class="recommend">
  85. <h3>推荐阅读</h3>
  86. <?php
  87. for ($i = 0; $i < 4; $i++) {
  88. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
  89. }
  90. for ($i = 0; $i < 4; $i++) {
  91. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
  92. }
  93. for ($i = 0; $i < 4; $i++) {
  94. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
  95. }
  96. for ($i = 0; $i < 4; $i++) {
  97. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
  98. }
  99. ?>
  100. </div>
  101. </div>
  102. <?php
  103. require __DIR__ . '/footer.php';
  104. ?>

article.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $article_id = $_GET['article_id'];
  4. $articles = $controller->select('article', 'view', 'articles','*','','',8);
  5. $article = $controller->find('article','view','articles','*','article_id='.$article_id);
  6. $reads = $controller->select('article', 'view', 'articles', '*', '', 'readership DESC', 6);
  7. $comments = $controller->select('article', 'view', 'articles', '*', '', 'comment_number DESC', 6);
  8. $recommends_img = [];
  9. $recommends_title = [];
  10. $recommends_id = [];
  11. foreach ($articles as $art) {
  12. if ($art->recommend == 1) {
  13. $recommends_img[] = $art->image;
  14. $recommends_title[] = $art->title;
  15. $recommends_id[] = $art->article_id;
  16. }
  17. }
  18. ?>
  19. <!DOCTYPE html>
  20. <html lang="en">
  21. <head>
  22. <meta charset="UTF-8">
  23. <title><?=$article->title?></title>
  24. <link rel="stylesheet" href="static/font/iconfont.css">
  25. <link rel="stylesheet" href="static/css/article.css">
  26. </head>
  27. <body>
  28. <?php
  29. require __DIR__ . '/header.php';
  30. ?>
  31. <div class="main">
  32. <div class="top">
  33. <img src="static/images/ar-logo.png" alt="">
  34. <a href=""><?=$article->cate?></a>&gt;<span>正文</span>
  35. <label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
  36. </div>
  37. <!-- 正文-->
  38. <article>
  39. <h1><?=$article->title?></h1>
  40. <div>
  41. <span>发布时间:<?=date('Y.m.d',$article->addtime)?></span>
  42. <span>来源:<?=$article->source?></span>
  43. <span>阅读量:<?=$article->readership?></span>
  44. <span>评论数:<?=$article->comment_number?></span>
  45. </div>
  46. <div>
  47. <?=$article->content?>
  48. </div>
  49. </article>
  50. <!-- 右侧列表-->
  51. <div class="list1">
  52. <h3>阅读量排行榜</h3>
  53. <ul>
  54. <?php
  55. foreach ($reads as $read) {
  56. echo '<li><a href="article.php?article_id=' . $read->article_id . '">' . $read->title . '</a></li>';
  57. }
  58. ?>
  59. </ul>
  60. </div>
  61. <div class="list2">
  62. <h3>评论数排行榜</h3>
  63. <ul>
  64. <?php
  65. foreach ($comments as $comment) {
  66. echo '<li><a href="article.php?article_id=' . $comment->article_id . '">' . $comment->title . '</a></li>';
  67. }
  68. ?>
  69. </ul>
  70. </div>
  71. <div class="ding">
  72. <span></span>
  73. <span></span>
  74. </div>
  75. <div class="comment">
  76. <h3>网页评论</h3>
  77. <img src="static/images/user.png" alt="" width="60">
  78. <textarea name="" id="" cols="30" rows="10"></textarea>
  79. <button>发表评论</button>
  80. </div>
  81. <div class="recommend">
  82. <h3>推荐阅读</h3>
  83. <?php
  84. for ($i = 0; $i < 4; $i++) {
  85. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
  86. }
  87. for ($i = 0; $i < 4; $i++) {
  88. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
  89. }
  90. for ($i = 0; $i < 4; $i++) {
  91. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
  92. }
  93. for ($i = 0; $i < 4; $i++) {
  94. echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
  95. }
  96. ?>
  97. </div>
  98. </div>
  99. <?php
  100. require __DIR__ . '/footer.php';
  101. ?>

image.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $pictures = $controller->select('picture', 'view', 'pictures');
  4. $picture_cate = [];
  5. foreach ($pictures as $picture){
  6. $picture_cate[] = $picture->cate;
  7. }
  8. $picture_cate = array_unique($picture_cate);
  9. $picture_cate = array_merge($picture_cate);
  10. ?>
  11. <!DOCTYPE html>
  12. <html lang="en">
  13. <head>
  14. <meta charset="UTF-8">
  15. <title>图片站首页</title>
  16. <link rel="stylesheet" href="static/font/iconfont.css">
  17. <link rel="stylesheet" href="static/css/image.css">
  18. </head>
  19. <body>
  20. <?php
  21. require __DIR__ . '/header.php';
  22. ?>
  23. <div class="top">
  24. <h2>PHP中文网<span>图片站</span></h2>
  25. <label>
  26. <input type="search">
  27. <a href="" class="iconfont icon-jinduchaxun"></a>
  28. </label>
  29. </div>
  30. <!-- 轮播图与列表-->
  31. <div class="slider">
  32. <img src="static/images/<?= $pictures[0]->image ?>" alt="" width="898" height="320">
  33. <div class="list1">
  34. <h3>今日推荐</h3>
  35. <ul>
  36. <?php
  37. for ($i = 0; $i < 6; $i++) {
  38. echo '<li><a href="image_content.php?picture_id=' . $pictures[$i]->picture_id . '">' . $pictures[$i]->name . '</a></li>';
  39. }
  40. ?>
  41. </ul>
  42. </div>
  43. </div>
  44. <div class="main">
  45. <!--图片专区1-->
  46. <div class="title">
  47. <span>图片专区1</span>
  48. </div>
  49. <div class="picture">
  50. <?php
  51. for($i=0;$i<3;$i++){
  52. echo '<div>';
  53. echo '<div><a href="">' . $picture_cate[$i] . ' <span>纵观摄影艺术</span></a></div>';
  54. $picture_img = [];
  55. $picture_name = [];
  56. $picture_id = [];
  57. foreach ($pictures as $picture) {
  58. if ($picture->cate == $picture_cate[$i]) {
  59. $picture_img[] = $picture->image;
  60. $picture_name[] = $picture->name;
  61. $picture_id[] = $picture->picture_id;
  62. }
  63. }
  64. for ($j = 0; $j < 2; $j++) {
  65. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
  66. }
  67. for ($j = 0; $j < 2; $j++) {
  68. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
  69. }
  70. for ($j = 2; $j< 4; $j++) {
  71. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
  72. }
  73. for ($j = 2; $j < 4; $j++) {
  74. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
  75. }
  76. echo '</div>';
  77. }
  78. ?>
  79. </div>
  80. <!--图片专区2-->
  81. <div class="title">
  82. <span>图片专区2</span>
  83. </div>
  84. <div class="picture">
  85. <?php
  86. for($i=0;$i<3;$i++){
  87. echo '<div>';
  88. echo '<div><a href="">' . $picture_cate[$i] . ' <span>纵观摄影艺术</span></a></div>';
  89. $picture_img = [];
  90. $picture_name = [];
  91. $picture_id = [];
  92. foreach ($pictures as $picture) {
  93. if ($picture->cate == $picture_cate[$i]) {
  94. $picture_img[] = $picture->image;
  95. $picture_name[] = $picture->name;
  96. $picture_id[] = $picture->picture_id;
  97. }
  98. }
  99. for ($j = 0; $j < 2; $j++) {
  100. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
  101. }
  102. for ($j = 0; $j < 2; $j++) {
  103. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
  104. }
  105. for ($j = 2; $j< 4; $j++) {
  106. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
  107. }
  108. for ($j = 2; $j < 4; $j++) {
  109. echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
  110. }
  111. echo '</div>';
  112. }
  113. ?>
  114. </div>
  115. </div>
  116. <?php
  117. require __DIR__ . '/footer.php';
  118. ?>

image_content.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $picture_id = $_GET['picture_id'];
  4. $picture = $controller->find('picture', 'view', 'pictures', '*', 'picture_id=' . $picture_id);
  5. $pictures = $controller->select('picture', 'view', 'pictures', '*', 'picture_id>' . $picture_id, '', 5);
  6. if (!is_array($pictures)){
  7. $pictures = [];
  8. }
  9. ?>
  10. <!DOCTYPE html>
  11. <html lang="en">
  12. <head>
  13. <meta charset="UTF-8">
  14. <title><?= $picture->name ?></title>
  15. <link rel="stylesheet" href="static/font/iconfont.css">
  16. <link rel="stylesheet" href="static/css/image-content.css">
  17. </head>
  18. <body>
  19. <?php
  20. require __DIR__ . '/header.php';
  21. ?>
  22. <div class="top">
  23. <h2>PHP中文网<span>图片站</span></h2>
  24. <label>
  25. <input type="search">
  26. <a href="" class="iconfont icon-jinduchaxun"></a>
  27. </label>
  28. </div>
  29. <div class="main">
  30. <div class="slider">
  31. <h2><?= $picture->name ?></h2>
  32. <div class="show">
  33. <img src="static/images/<?= $picture->image ?>" alt="" height="300" width="800">
  34. </div>
  35. <div class="thumb">
  36. <?php
  37. foreach ($pictures as $picture) {
  38. echo '<a href=""><img src="static/images/' . $picture->image . '" alt="" width="160" height="90"></a>';
  39. }
  40. ?>
  41. </div>
  42. </div>
  43. <!--评论复制文章详情页代码-->
  44. <div class="comment">
  45. <h3>网页评论</h3>
  46. <img src="static/images/user.png" alt="" width="60">
  47. <textarea name="" id="" cols="30" rows="10"></textarea>
  48. <button>发表评论</button>
  49. </div>
  50. <!--最新评论-->
  51. <div class="reply">
  52. <h3>最新评论</h3>
  53. <div>
  54. <img src="static/images/user.png" alt="" width="60" height="60">
  55. <span>用户昵称</span>
  56. <span>留言内容</span>
  57. <div>
  58. <span>2019-12-12 15:34:23发表</span>
  59. <span><i class="iconfont icon-dianzan"></i>回复</span>
  60. </div>
  61. </div>
  62. <div>
  63. <img src="static/images/user.png" alt="" width="60" height="60">
  64. <span>用户昵称</span>
  65. <span>留言内容</span>
  66. <div>
  67. <span>2019-12-12 15:34:23发表</span>
  68. <span><i class="iconfont icon-dianzan"></i>回复</span>
  69. </div>
  70. </div>
  71. <div>
  72. <img src="static/images/user.png" alt="" width="60" height="60">
  73. <span>用户昵称</span>
  74. <span>留言内容</span>
  75. <div>
  76. <span>2019-12-12 15:34:23发表</span>
  77. <span><i class="iconfont icon-dianzan"></i>回复</span>
  78. </div>
  79. </div>
  80. <div>
  81. <img src="static/images/user.png" alt="" width="60" height="60">
  82. <span>用户昵称</span>
  83. <span>留言内容</span>
  84. <div>
  85. <span>2019-12-12 15:34:23发表</span>
  86. <span><i class="iconfont icon-dianzan"></i>回复</span>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <?php
  92. require __DIR__ . '/footer.php';
  93. ?>

shop.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $goods = $controller->select('good','view','goods');
  4. $goods_cate = [];
  5. foreach ($goods as $good){
  6. $goods_cate[] = $good->cate;
  7. }
  8. $goods_cate = array_unique($goods_cate);
  9. $goods_cate = array_merge($goods_cate);
  10. ?>
  11. <!DOCTYPE html>
  12. <html lang="en">
  13. <head>
  14. <meta charset="UTF-8">
  15. <title>商城首页</title>
  16. <link rel="stylesheet" href="static/font/iconfont.css">
  17. <link rel="stylesheet" href="static/css/shop.css">
  18. </head>
  19. <body>
  20. <?php
  21. require __DIR__ . '/header.php';
  22. ?>
  23. <!--logo+搜索框+快捷入口区-->
  24. <div class="logo">
  25. <img src="static/images/logo.png" alt="">
  26. <input type="search" id="search"><label for="search">搜索</label>
  27. <a href="">免费入驻</a>
  28. </div>
  29. <!--轮播图-->
  30. <div class="slider">
  31. <nav>
  32. <h3>所有产品分类 <span class="iconfont icon-liebiao"></span></h3>
  33. <div>
  34. <a href="">企业软件</a>
  35. <a href="">微信推广</a>
  36. <a href="">QQ推广</a>
  37. <a href="">公众号推广</a>
  38. <a href="">海客软件</a>
  39. <a href="">网络推广</a>
  40. <a href="">SEO软件</a>
  41. </div>
  42. <div>
  43. <a href="">企业软件</a>
  44. <a href="">微信推广</a>
  45. <a href="">QQ推广</a>
  46. <a href="">公众号推广</a>
  47. <a href="">海客软件</a>
  48. <a href="">网络推广</a>
  49. <a href="">SEO软件</a>
  50. </div>
  51. <div>
  52. <a href="">企业软件</a>
  53. <a href="">微信推广</a>
  54. <a href="">QQ推广</a>
  55. <a href="">公众号推广</a>
  56. <a href="">海客软件</a>
  57. <a href="">网络推广</a>
  58. <a href="">SEO软件</a>
  59. </div>
  60. </nav>
  61. <div>
  62. <div>
  63. <a href="" class="active">首页</a>
  64. <a href="">3C</a>
  65. <a href="">生活用品</a><sup class="badge"></sup>
  66. <a href="">名字名画</a>
  67. </div>
  68. <img src="static/images/4.jpg" alt="" width="900" height="398">
  69. </div>
  70. </div>
  71. <!--手机交易区-->
  72. <div class="title">
  73. <span><?=$goods_cate[0]?></span>
  74. </div>
  75. <div class="second-hand">
  76. <div>
  77. <a href="">抢好货</a>
  78. <span>0低价, 便捷,安全,快速</span>
  79. </div>
  80. <div>
  81. <span>热门分类</span>
  82. <a href="">美女写真</a>
  83. <a href="">日本美女</a>
  84. <a href="">美国美女</a>
  85. <a href="">国内美女</a>
  86. <a href="">AV美女</a>
  87. </div>
  88. <?php
  89. $good_img = [];
  90. $good_name = [];
  91. $good_price = [];
  92. $good_id = [];
  93. foreach ($goods as $good){
  94. if ($good->cate == $goods_cate[0]){
  95. $good_img[] = $good->image;
  96. $good_name[] = $good->name;
  97. $good_price[] = $good->price;
  98. $good_id[] = $good->good_id;
  99. }
  100. }
  101. for ($i=0;$i<4;$i++){
  102. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  103. }
  104. for ($i=0;$i<4;$i++){
  105. echo '<div class="detail">';
  106. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  107. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
  108. echo '</div>';
  109. }
  110. for ($i=4;$i<8;$i++){
  111. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  112. }
  113. for ($i=4;$i<8;$i++){
  114. echo '<div class="detail">';
  115. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  116. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
  117. echo '</div>';
  118. }
  119. ?>
  120. <div>
  121. <a href=""><img src="static/images/ad/1.png" alt="" width="180" height="112"></a>
  122. <a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
  123. <a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
  124. <a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
  125. <a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
  126. <a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
  127. </div>
  128. </div>
  129. <!--电脑交易区1-->
  130. <div class="title">
  131. <span><?=$goods_cate[1]?></span>
  132. </div>
  133. <div class="mirror">
  134. <div>
  135. <a href="">抢好货</a>
  136. <span>0低价, 便捷,安全,快速</span>
  137. </div>
  138. <div>
  139. <span>热门分类</span>
  140. <a href="">美女写真</a>
  141. <a href="">日本美女</a>
  142. <a href="">美国美女</a>
  143. <a href="">国内美女</a>
  144. <a href="">AV美女</a>
  145. </div>
  146. <?php
  147. $good_img = [];
  148. $good_name = [];
  149. $good_price = [];
  150. $good_id = [];
  151. foreach ($goods as $good){
  152. if ($good->cate == $goods_cate[1]){
  153. $good_img[] = $good->image;
  154. $good_name[] = $good->name;
  155. $good_price[] = $good->price;
  156. $good_id[] = $good->good_id;
  157. }
  158. }
  159. for ($i=0;$i<6;$i++){
  160. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  161. }
  162. for ($i=0;$i<6;$i++){
  163. echo '<div class="detail">';
  164. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  165. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
  166. echo '</div>';
  167. }
  168. for ($i=6;$i<12;$i++){
  169. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  170. }
  171. for ($i=6;$i<12;$i++){
  172. echo '<div class="detail">';
  173. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  174. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
  175. echo '</div>';
  176. }
  177. ?>
  178. </div>
  179. <!--电脑交易区2-->
  180. <div class="title">
  181. <span><?=$goods_cate[1]?></span>
  182. </div>
  183. <div class="mirror">
  184. <div>
  185. <a href="">抢好货</a>
  186. <span>0低价, 便捷,安全,快速</span>
  187. </div>
  188. <div>
  189. <span>热门分类</span>
  190. <a href="">美女写真</a>
  191. <a href="">日本美女</a>
  192. <a href="">美国美女</a>
  193. <a href="">国内美女</a>
  194. <a href="">AV美女</a>
  195. </div>
  196. <?php
  197. $good_img = [];
  198. $good_name = [];
  199. $good_price = [];
  200. $good_id = [];
  201. foreach ($goods as $good){
  202. if ($good->cate == $goods_cate[1]){
  203. $good_img[] = $good->image;
  204. $good_name[] = $good->name;
  205. $good_price[] = $good->price;
  206. $good_id[] = $good->good_id;
  207. }
  208. }
  209. for ($i=0;$i<6;$i++){
  210. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  211. }
  212. for ($i=0;$i<6;$i++){
  213. echo '<div class="detail">';
  214. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  215. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
  216. echo '</div>';
  217. }
  218. for ($i=6;$i<12;$i++){
  219. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
  220. }
  221. for ($i=6;$i<12;$i++){
  222. echo '<div class="detail">';
  223. echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
  224. echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>&yen; ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
  225. echo '</div>';
  226. }
  227. ?>
  228. </div>
  229. <?php
  230. require __DIR__ . '/footer.php';
  231. ?>

shop_content.php

  1. <?php
  2. require __DIR__ . '/common.php';
  3. $good_id = $_GET['good_id'];
  4. $good = $controller->find('good', 'view', 'goods', '*', 'good_id=' . $good_id);
  5. $goods = $controller->select('good','view','goods','*','cate="' . $good->cate . '"' ,'sales DESC',5);
  6. ?>
  7. <!DOCTYPE html>
  8. <html lang="en">
  9. <head>
  10. <meta charset="UTF-8">
  11. <title><?=$good->name?></title>
  12. <link rel="stylesheet" href="static/font/iconfont.css">
  13. <link rel="stylesheet" href="static/css/shop-content.css">
  14. </head>
  15. <body>
  16. <?php
  17. require __DIR__ . '/header.php';
  18. ?>
  19. <!--logo+搜索框+快捷入口区-->
  20. <div class="logo">
  21. <img src="static/images/logo.png" alt="">
  22. <input type="search" id="search"><label for="search">搜索</label>
  23. <a href="">免费入驻</a>
  24. </div>
  25. <main>
  26. <!--导航-->
  27. <nav>
  28. <h3>所有产品分类 <span class="iconfont icon-liebiao"></span></h3>
  29. <a href="" class="active">首页</a>
  30. <a href="">3C</a>
  31. <a href="">生活用品</a>
  32. <a href="">名字名画</a>
  33. </nav>
  34. <!-- 商品展示-->
  35. <div class="goods">
  36. <div class="top-nav">
  37. <a href="">首页</a>-&gt;&gt;
  38. <a href="">3C数码</a>-&gt;&gt;
  39. <a href=""><?=$good->cate?></a>-&gt;&gt;
  40. </div>
  41. <img src="static/images/<?=$good->image?>" alt="">
  42. <h2><?=$good->name?></h2>
  43. <p>本站特惠: <span>&yen;<?=$good->price?></span></p>
  44. <p>
  45. 销量: <span><?=$good->sales?></span>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
  46. 累积评价: <span><?=$good->judge?></span>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
  47. 好评率: <span><?=$good->good_ratings?>%</span>
  48. </p>
  49. <p>
  50. <label for="num">购买数量:</label><input type="number" id="num" value="1">
  51. </p>
  52. <div>
  53. <button>立即购买</button>
  54. <button><i class="iconfont icon-icon_tianjia"></i>加入购物车</button>
  55. </div>
  56. <div>
  57. <span><i class="iconfont icon-zhanghaoquanxianguanli"></i>本站保障</span>
  58. <span><i class="iconfont icon-icon_safety"></i>企业认证</span>
  59. <span><i class="iconfont icon-tianshenpi"></i>退款承诺</span>
  60. <span><i class="iconfont icon-kuaisubianpai"></i>免费换货</span>
  61. </div>
  62. </div>
  63. <!-- 商品详情-->
  64. <div class="detail">
  65. <aside>
  66. <div><span>商品推荐</span><span>其它热销</span></div>
  67. <?php
  68. foreach ($goods as $gd){
  69. echo '<div>';
  70. echo '<a href="shop_content.php?good_id=' . $gd->good_id . '"><img src="static/images/' . $gd->image . '" alt=""></a>';
  71. echo '<a href="">' . mb_substr($gd->name, 0, 20, "utf-8") . '...</a>';
  72. echo '<div><span>热销:' . $gd->sales . '</span><span>&yen;' . $gd->price . '</span></div>';
  73. echo '</div>';
  74. }
  75. ?>
  76. </aside>
  77. <article>
  78. <div class="nav">
  79. <a href="">商品详情</a>
  80. <a href="">案例/演示</a>
  81. <a href="">常见问题</a>
  82. <a href="">累计评价</a>
  83. <a href="">产品咨询</a>
  84. </div>
  85. <div class="content">
  86. <?=$good->detail?>
  87. </div>
  88. <div class="comment">
  89. <h3>网页评论</h3>
  90. <img src="static/images/user.png" alt="" width="60">
  91. <textarea name="" id="" cols="30" rows="10"></textarea>
  92. <button>发表评论</button>
  93. </div>
  94. <!-- 最新评论-->
  95. <div>
  96. <h3>最新评论</h3>
  97. <div>
  98. <img src="static/images/user.png" alt="" width="60" height="60">
  99. <span>用户昵称</span>
  100. <span>留言内容</span>
  101. <div>
  102. <span>2019-12-12 15:34:23发表</span>
  103. <span><i class="iconfont icon-dianzan"></i>回复</span>
  104. </div>
  105. </div>
  106. <div>
  107. <img src="static/images/user.png" alt="" width="60" height="60">
  108. <span>用户昵称</span>
  109. <span>留言内容</span>
  110. <div>
  111. <span>2019-12-12 15:34:23发表</span>
  112. <span><i class="iconfont icon-dianzan"></i>回复</span>
  113. </div>
  114. </div>
  115. <div>
  116. <img src="static/images/user.png" alt="" width="60" height="60">
  117. <span>用户昵称</span>
  118. <span>留言内容</span>
  119. <div>
  120. <span>2019-12-12 15:34:23发表</span>
  121. <span><i class="iconfont icon-dianzan"></i>回复</span>
  122. </div>
  123. </div>
  124. <div>
  125. <img src="static/images/user.png" alt="" width="60" height="60">
  126. <span>用户昵称</span>
  127. <span>留言内容</span>
  128. <div>
  129. <span>2019-12-12 15:34:23发表</span>
  130. <span><i class="iconfont icon-dianzan"></i>回复</span>
  131. </div>
  132. </div>
  133. </div>
  134. </article>
  135. </div>
  136. </main>
  137. <?php
  138. require __DIR__ . '/footer.php';
  139. ?>

4. 效果展示







5. 总结

很多地方写的还是很繁琐,视图类没有起到真正渲染模板的作用,仅用于返回数据,还是得加强学习。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议