Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:完成的很认真
Db.php
<?php
// 定义命名空间
namespace project\model;
// 引入类的别名
use PDO;
use PDOException;
// 用于连接数据库
class Db
{
// 连接属性
public static $pdo = null;
// 构造方法私有化
// 在构造方法中实现连接数据库
private function __construct()
{
try {
self::$pdo = new PDO('mysql:host=localhost;dbname=php','root','root');
}catch (PDOException $e){
die('数据库连接失败,错误信息为:' . $e->getMessage());
}
}
public static function getInstance()
{
if (is_null(self::$pdo)){
new self();
}
return self::$pdo;
}
// 克隆方法私有化
private function __clone()
{
}
}
Model.php
<?php
// 定义命名空间
namespace project\model;
// 引入Db类文件
//require 'Db.php';
use PDO;
// 公共模型类
class Model
{
// 连接属性
public $pdo = null;
// 获取当前类名
public $className = self::class;
// 构造方法实现自动连接数据库
public function __construct()
{
$this->pdo = Db::getInstance();
}
// 查询多条记录
public function select($table, $fields = '*', $where = '', $order = '', $limit = '')
{
// 创建SQL语句
$sql = 'SELECT ';
if (is_array($fields)) {
foreach ($fields as $field) {
$sql .= $field . ', ';
}
} else {
$sql .= $fields;
}
$sql = rtrim(trim($sql), ',');
$sql .= ' FROM ' . $table;
// 查询条件
if (!empty($where)) {
$sql .= ' WHERE ' . $where;
}
// 排序方式
if (!empty($order)) {
$sql .= ' ORDER BY ' . $order;
}
// 分页
if (!empty($limit)) {
$sql .= ' LIMIT ' . $limit;
}
$sql .= ';';
// 创建PDO预处理对象
$stmt = $this->pdo->prepare($sql);
// 执行查询操作
if ($stmt->execute()) {
if ($stmt->rowCount() > 0) {
$stmt->setFetchMode(PDO::FETCH_CLASS, $this->className);
return $stmt->fetchAll();
}
}
return '查询失败';
}
// 查询单条记录
public function find($table, $fields, $where = '')
{
$sql = 'SELECT ';
if (is_array($fields)) {
foreach ($fields as $field) {
$sql .= $field . ', ';
}
} else {
$sql .= $fields;
}
$sql = rtrim(trim($sql), ',');
$sql .= ' FROM ' . $table;
if (!empty($where)) {
$sql .= ' WHERE ' . $where;
}
$sql .= ' LIMIT 1;';
$stmt = $this->pdo->prepare($sql);
if ($stmt->execute()) {
if ($stmt->rowCount() > 0) {
$stmt->setFetchMode(PDO::FETCH_CLASS, $this->className);
return $stmt->fetch();
}
}
return '查询失败';
}
public function __destruct()
{
$this->pdo = null;
}
}
Article.php
<?php
namespace project\model;
class Article extends Model
{
public $addtime;
public $className = self::class;
public function setData()
{
$t = time();
if ($t - $this->addtime < 60) {
return ($t - $this->addtime) . '秒'; // 秒
} else if ($t - $this->addtime < 60 * 60) {
return round((($t - $this->addtime) / 60)-0.5) . '分钟'; // 分
} else if ($t - $this->addtime < 24 * 60 * 60) {
return round((($t - $this->addtime) / (60 * 60))-0.5) . '小时'; // 时
} else if ($t - $this->addtime < 7 * 24 * 60 * 60) {
return round((($t - $this->addtime) / (24 * 60 * 60))-0.5) . '天'; // 天
} else if ($t - $this->addtime < 30 * 7 * 24 * 60 * 60) {
return round((($t - $this->addtime) / (7 * 24 * 60 * 60))-0.5) . '星期'; // 周
} else if ($t - $this->addtime < 365 * 30 * 7 * 24 * 60 * 60) {
return round((($t - $this->addtime) / (30 * 7 * 24 * 60 * 60))-0.5) . '月'; // 月
} else {
return round((($t - $this->addtime) / (365 * 30 * 7 * 24 * 60 * 60))-0.5) . '年'; // 年
}
}
}
Good.php
<?php
namespace project\model;
class Good extends Model
{
public $className = self::class;
}
Picture.php
<?php
namespace project\model;
class Picture extends Model
{
public $className = self::class;
}
View.php
<?php
namespace project\view;
// 视图类
class View
{
// 获取数据,并将数据返回
public function data($data)
{
return $data;
}
}
Container.php
<?php
namespace project\controller;
use Closure;
// 服务容器类
class Container
{
// 容器属性:用来保存创建对象的方法
protected $instance = [];
// 将类的实例化过程绑定到容器中
public function bind($alias, Closure $process)
{
$this->instance[$alias] = $process;
}
// 执行容器中的实例化方法
public function make($alias,$params=[])
{
return call_user_func_array($this->instance[$alias],$params);
}
}
Facade.php
<?php
namespace project\controller;
// 门面类
class Facade
{
protected static $container = null;
protected static $data = [];
// 用服务容器将静态属性初始化
public static function initialize(Container $container)
{
static::$container = $container;
}
// 用静态代理的方式将模型类中的 select() 方法静态化
public static function select($model, $table, $fields = '*', $where = '', $order = '', $limit = '')
{
static::$data = static::$container->make($model)->select($table, $fields, $where, $order, $limit);
}
// 用静态代理的方式将模型类中的 find() 静态化
public static function find($model, $table, $fields, $where = '')
{
static::$data = static::$container->make($model)->find($table, $fields, $where);
}
// 用静态代理的方式将视图类中的 data() 静态化
public static function data($view)
{
return static::$container->make($view)->data(static::$data);
}
}
Controller.php
<?php
namespace project\controller;
// 控制器类
class Controller
{
// 使用构造方法,自动调用Facade类里面的初始化方法
public function __construct(Container $container)
{
Facade::initialize($container);
}
// 查询多条数据
public function select($model, $view, $table, $fields = '*', $where = '', $order = '', $limit = '')
{
Facade::select($model, $table, $fields, $where, $order, $limit);
return Facade::data($view);
}
// 查询单条数据
public function find($model, $view, $table, $fields, $where = '')
{
Facade::find($model,$table,$fields,$where);
return Facade::data($view);
}
}
common.php
<?php
namespace project;
use project\controller\Controller;
use project\controller\Container;
use project\model\Article;
use project\model\Good;
use project\model\Picture;
use project\view\View;
require __DIR__ . '/autoload.php';
$container = new Container();
$container->bind('article', function () {
return new Article();
});
$container->bind('picture',function (){
return new Picture();
});
$container->bind('good',function (){
return new Good();
});
$container->bind('view', function () {
return new View();
});
$controller = new Controller($container);
header.php
<!--公共顶部导航区-->
<header>
<a href="index.php">网站首页</a>
<a href="article_list.php">文章专题</a>
<a href="image.php">图片站</a>
<a href="shop.php">二手商品</a>
<a href="">讨论区</a>
<span><a href=""><i class="iconfont icon-huiyuan2"></i>登陆</a><a href="">免费注册</a></span>
</header>
footrt.php
<!--页底部-->
<footer>
<div>
<a href="">简介</a>
<a href="">联系我们</a>
<a href="">招聘信息</a>
<a href="">友情链接</a>
<a href="">用户服务协议</a>
<a href="">隐私权声明</a>
<a href="">法律投诉声明</a>
</div>
<div><span>LOGO</span></div>
<div>
<p>2019 fengniao.com. All rights reserved . 安徽闹着玩有限公司(无聊网)版权所有</p>
<p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
<p>违法和不良信息举报电话: 0551-1234567 举报邮箱: admin@baidu.com</p>
</div>
<div>
<p>关注公众号</p>
<img src="static/images/erwei-code.png" alt="">
</div>
</footer>
</body>
</html>
autoload.php
<?php
namespace project_test;
// 类的自动加载
spl_autoload_register(function ($className){
$path = str_replace('\\', '/', $className);
require dirname(__DIR__) . DIRECTORY_SEPARATOR . $path . '.php';
});
index.php
<?php
require __DIR__ . '/common.php';
$article1s = $controller->select('article', 'view', 'articles', '*', 'recommend=1');
$article2s = $controller->select('article', 'view', 'articles', '*', 'recommend=0');
$goods = $controller->select('good', 'view', 'goods');
$goods_cate = [];
foreach ($goods as $good){
$goods_cate[] = $good->cate;
}
$goods_cate = array_unique($goods_cate);
$goods_cate = array_merge($goods_cate);
$pictures = $controller->select('picture', 'view', 'pictures');
$picture_cate = [];
foreach ($pictures as $picture){
$picture_cate[] = $picture->cate;
}
$picture_cate = array_unique($picture_cate);
$picture_cate = array_merge($picture_cate);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页</title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/index.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<!--logo+搜索框+快捷入口区-->
<div class="logo">
<img src="static/images/logo.png" alt="">
<label>
<input type="search">
<a href="" class="iconfont icon-jinduchaxun"></a>
</label>
<span>
<a href="" class="iconfont icon-huiyuan1"></a>
<a href="" class="iconfont icon-danmu"></a>
<a href="" class="iconfont icon-duoxuankuang"></a>
<a href="" class="iconfont icon-jishufuwu"></a>
<a href="" class="iconfont icon-peiwangyindao"></a>
<a href="" class="iconfont icon-wenjianjia"></a>
<a href="" class="iconfont icon-huiyuan1"></a>
</span>
</div>
<!--主导航区-->
<nav>
<div>
<span class="iconfont icon-gongdan"></span>
<span>资讯 <br> 看学</span>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
</div>
<div>
<span class="iconfont icon-renwujincheng"></span>
<span>资讯 <br> 看学</span>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
</div>
<div>
<span class="iconfont icon-gongdan"></span>
<span>资讯 <br> 看学</span>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
</div>
<div>
<span class="iconfont icon-DOC"></span>
<span>资讯 <br> 看学</span>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
<a href="">器材</a>
<a href="">大师</a>
<a href="">学院</a>
<a href="">影赛</a>
</div>
</nav>
<!--轮播图-->
<div class="slider">
<img src="static/images/1.jpg" alt="">
<img src="static/images/banner-right.jpg" alt="">
</div>
<!--新闻资讯区-->
<div class="news">
<div class="title">
<a>新闻资讯</a>
<a href="">更多</a>
</div>
<div class="content">
<div class="pic">
<a href="article.php?article_id=<?= $article1s[0]->article_id ?>"><img
src="static/images/<?= $article1s[0]->image ?>" alt="" class="first-img" width="380"
height="160"></a>
<a href="article.php?article_id=<?= $article1s[1]->article_id ?>"><img
src="static/images/<?= $article1s[1]->image ?>" alt=""></a>
<a href="article.php?article_id=<?= $article1s[2]->article_id ?>"><img
src="static/images/<?= $article1s[2]->image ?>" alt=""></a>
<a href="article.php?article_id=<?= $article1s[1]->article_id ?>"><?= $article1s[1]->title ?></a>
<a href="article.php?article_id=<?= $article1s[2]->article_id ?>"><?= $article1s[2]->title ?></a>
</div>
<div class="list">
<a href="article.php?article_id=<?= $article1s[3]->article_id ?>"><?= $article1s[3]->title ?></a>
<ul>
<?php
$i = 0;
foreach ($article2s as $article) {
echo '<li><span>[新闻]</span><a href="article.php?article_id=' . $article->article_id . '">' . $article->title . '</a></li>';
$i++;
if($i == 9){
break;
}
}
?>
</ul>
</div>
<div class="list">
<a href="article.php?article_id=<?= $article1s[3]->article_id ?>"><?= $article1s[3]->title ?></a>
<ul>
<?php
$i = 0;
foreach ($article2s as $article) {
echo '<li><span>[新闻]</span><a href="article.php?article_id=' . $article->article_id . '">' . $article->title . '</a></li>';
$i++;
if($i == 9){
break;
}
}
?>
</ul>
</div>
</div>
</div>
<!--图片专区-->
<div class="title">
<span>图片专区</span>
</div>
<div class="picture">
<?php
for($i=0;$i<3;$i++){
echo '<div>';
echo '<div><a href="">' . $picture_cate[$i] . ' <span>纵观摄影艺术</span></a></div>';
$picture_img = [];
$picture_name = [];
$picture_id = [];
foreach ($pictures as $picture) {
if ($picture->cate == $picture_cate[$i]) {
$picture_img[] = $picture->image;
$picture_name[] = $picture->name;
$picture_id[] = $picture->picture_id;
}
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
for ($j = 2; $j< 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 2; $j < 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
echo '</div>';
}
?>
</div>
<!--二手交易专区-->
<div class="title">
<span>二手交易</span>
</div>
<div class="second-hand">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<?php
$good_img = [];
$good_name = [];
$good_price = [];
$good_id = [];
foreach ($goods as $good){
if ($good->cate == $goods_cate[0]){
$good_img[] = $good->image;
$good_name[] = $good->name;
$good_price[] = $good->price;
$good_id[] = $good->good_id;
}
}
for ($i=0;$i<4;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=0;$i<4;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
echo '</div>';
}
for ($i=4;$i<8;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=4;$i<8;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
echo '</div>';
}
?>
<div>
<a href=""><img src="static/images/ad/1.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
<a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
</div>
</div>
<!--合作网站-->
<div class="title" style="background:#fff">
<span>合作网站</span>
</div>
<div class="my-links">
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.php.cn">php中文网</a>
<a href="https://www.html.cn">html中文网</a>
<a href="https://www.py.cn">python中文网</a>
<a href="https://www.py.cn">python中文网</a>
</div>
<?php
require __DIR__ . '/footer.php';
?>
article_list.php
<?php
require __DIR__ . '/common.php';
$articles = $controller->select('article', 'view', 'articles','*','','',8);
$reads = $controller->select('article', 'view', 'articles', '*', '', 'readership DESC', 6);
$comments = $controller->select('article', 'view', 'articles', '*', '', 'comment_number DESC', 6);
$recommends_img = [];
$recommends_title = [];
$recommends_id = [];
foreach ($articles as $article) {
if ($article->recommend == 1) {
$recommends_img[] = $article->image;
$recommends_title[] = $article->title;
$recommends_id[] = $article->article_id;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>文章列表页</title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/article-list.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<div class="main">
<div class="top">
<img src="static/images/ar-logo.png" alt="">
<label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
</div>
<!-- 列表-->
<article>
<div>
<a href="">头条</a>
<a href="">热文</a>
<a href="">直播</a>
<a href="" id="active">新闻</a>
<a href="">政策地图</a>
<a href="">相对论</a>
<a href="">人物</a>
<a href="">行情</a>
<a href="">投研</a>
<a href="">技术</a>
<a href="">百科</a>
</div>
<?php
foreach ($articles as $article) {
echo '<div class="list1">';
echo '<a href="article.php?article_id=' . $article->article_id . '"><img src="static/images/' . $article->image . '" alt="" width="272" height="180"></a>';
echo '<div>';
echo '<a href="article.php?article_id=' . $article->article_id . '">' . $article->title . '</a>';
echo '<span>' . mb_substr($article->content, 0, 50, "utf-8") . '...</span>';
echo '</div>';
echo '<a href="">' . $article->cate . ' · ' . $article->setData() . '前</a>';
echo '<span><i class="iconfont icon-icon_yulan"></i>' . $article->readership . '</span>';
echo '</div>';
}
?>
</article>
<!-- 右侧列表-->
<div class="list1">
<h3>阅读量排行榜</h3>
<ul>
<?php
foreach ($reads as $read) {
echo '<li><a href="article.php?article_id=' . $read->article_id . '">' . $read->title . '</a></li>';
}
?>
</ul>
</div>
<div class="list2">
<h3>评论数排行榜</h3>
<ul>
<?php
foreach ($comments as $comment) {
echo '<li><a href="article.php?article_id=' . $comment->article_id . '">' . $comment->title . '</a></li>';
}
?>
</ul>
</div>
<div class="recommend">
<h3>推荐阅读</h3>
<?php
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
}
?>
</div>
</div>
<?php
require __DIR__ . '/footer.php';
?>
article.php
<?php
require __DIR__ . '/common.php';
$article_id = $_GET['article_id'];
$articles = $controller->select('article', 'view', 'articles','*','','',8);
$article = $controller->find('article','view','articles','*','article_id='.$article_id);
$reads = $controller->select('article', 'view', 'articles', '*', '', 'readership DESC', 6);
$comments = $controller->select('article', 'view', 'articles', '*', '', 'comment_number DESC', 6);
$recommends_img = [];
$recommends_title = [];
$recommends_id = [];
foreach ($articles as $art) {
if ($art->recommend == 1) {
$recommends_img[] = $art->image;
$recommends_title[] = $art->title;
$recommends_id[] = $art->article_id;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?=$article->title?></title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/article.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<div class="main">
<div class="top">
<img src="static/images/ar-logo.png" alt="">
<a href=""><?=$article->cate?></a>><span>正文</span>
<label><input type="search"><span class="iconfont icon-sousuo2"></span></label>
</div>
<!-- 正文-->
<article>
<h1><?=$article->title?></h1>
<div>
<span>发布时间:<?=date('Y.m.d',$article->addtime)?></span>
<span>来源:<?=$article->source?></span>
<span>阅读量:<?=$article->readership?></span>
<span>评论数:<?=$article->comment_number?></span>
</div>
<div>
<?=$article->content?>
</div>
</article>
<!-- 右侧列表-->
<div class="list1">
<h3>阅读量排行榜</h3>
<ul>
<?php
foreach ($reads as $read) {
echo '<li><a href="article.php?article_id=' . $read->article_id . '">' . $read->title . '</a></li>';
}
?>
</ul>
</div>
<div class="list2">
<h3>评论数排行榜</h3>
<ul>
<?php
foreach ($comments as $comment) {
echo '<li><a href="article.php?article_id=' . $comment->article_id . '">' . $comment->title . '</a></li>';
}
?>
</ul>
</div>
<div class="ding">
<span>赞</span>
<span>踩</span>
</div>
<div class="comment">
<h3>网页评论</h3>
<img src="static/images/user.png" alt="" width="60">
<textarea name="" id="" cols="30" rows="10"></textarea>
<button>发表评论</button>
</div>
<div class="recommend">
<h3>推荐阅读</h3>
<?php
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '"><img src="static/images/' . $recommends_img[$i] . '" alt="" width="195" height="130"></a>';
}
for ($i = 0; $i < 4; $i++) {
echo '<a href="article.php?article_id=' . $recommends_id[$i] . '">' . $recommends_title[$i] . '</a>';
}
?>
</div>
</div>
<?php
require __DIR__ . '/footer.php';
?>
image.php
<?php
require __DIR__ . '/common.php';
$pictures = $controller->select('picture', 'view', 'pictures');
$picture_cate = [];
foreach ($pictures as $picture){
$picture_cate[] = $picture->cate;
}
$picture_cate = array_unique($picture_cate);
$picture_cate = array_merge($picture_cate);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片站首页</title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/image.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<div class="top">
<h2>PHP中文网<span>图片站</span></h2>
<label>
<input type="search">
<a href="" class="iconfont icon-jinduchaxun"></a>
</label>
</div>
<!-- 轮播图与列表-->
<div class="slider">
<img src="static/images/<?= $pictures[0]->image ?>" alt="" width="898" height="320">
<div class="list1">
<h3>今日推荐</h3>
<ul>
<?php
for ($i = 0; $i < 6; $i++) {
echo '<li><a href="image_content.php?picture_id=' . $pictures[$i]->picture_id . '">' . $pictures[$i]->name . '</a></li>';
}
?>
</ul>
</div>
</div>
<div class="main">
<!--图片专区1-->
<div class="title">
<span>图片专区1</span>
</div>
<div class="picture">
<?php
for($i=0;$i<3;$i++){
echo '<div>';
echo '<div><a href="">' . $picture_cate[$i] . ' <span>纵观摄影艺术</span></a></div>';
$picture_img = [];
$picture_name = [];
$picture_id = [];
foreach ($pictures as $picture) {
if ($picture->cate == $picture_cate[$i]) {
$picture_img[] = $picture->image;
$picture_name[] = $picture->name;
$picture_id[] = $picture->picture_id;
}
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
for ($j = 2; $j< 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 2; $j < 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
echo '</div>';
}
?>
</div>
<!--图片专区2-->
<div class="title">
<span>图片专区2</span>
</div>
<div class="picture">
<?php
for($i=0;$i<3;$i++){
echo '<div>';
echo '<div><a href="">' . $picture_cate[$i] . ' <span>纵观摄影艺术</span></a></div>';
$picture_img = [];
$picture_name = [];
$picture_id = [];
foreach ($pictures as $picture) {
if ($picture->cate == $picture_cate[$i]) {
$picture_img[] = $picture->image;
$picture_name[] = $picture->name;
$picture_id[] = $picture->picture_id;
}
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 0; $j < 2; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
for ($j = 2; $j< 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><img src="static/images/' . $picture_img[$j] . '" alt="" width="162" height="122"></a>';
}
for ($j = 2; $j < 4; $j++) {
echo '<a href="image_content.php?picture_id=' . $picture_id[$j] . '"><span>' . $picture_name[$j] . '</span></a>';
}
echo '</div>';
}
?>
</div>
</div>
<?php
require __DIR__ . '/footer.php';
?>
image_content.php
<?php
require __DIR__ . '/common.php';
$picture_id = $_GET['picture_id'];
$picture = $controller->find('picture', 'view', 'pictures', '*', 'picture_id=' . $picture_id);
$pictures = $controller->select('picture', 'view', 'pictures', '*', 'picture_id>' . $picture_id, '', 5);
if (!is_array($pictures)){
$pictures = [];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?= $picture->name ?></title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/image-content.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<div class="top">
<h2>PHP中文网<span>图片站</span></h2>
<label>
<input type="search">
<a href="" class="iconfont icon-jinduchaxun"></a>
</label>
</div>
<div class="main">
<div class="slider">
<h2><?= $picture->name ?></h2>
<div class="show">
<img src="static/images/<?= $picture->image ?>" alt="" height="300" width="800">
</div>
<div class="thumb">
<?php
foreach ($pictures as $picture) {
echo '<a href=""><img src="static/images/' . $picture->image . '" alt="" width="160" height="90"></a>';
}
?>
</div>
</div>
<!--评论复制文章详情页代码-->
<div class="comment">
<h3>网页评论</h3>
<img src="static/images/user.png" alt="" width="60">
<textarea name="" id="" cols="30" rows="10"></textarea>
<button>发表评论</button>
</div>
<!--最新评论-->
<div class="reply">
<h3>最新评论</h3>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
</div>
<?php
require __DIR__ . '/footer.php';
?>
shop.php
<?php
require __DIR__ . '/common.php';
$goods = $controller->select('good','view','goods');
$goods_cate = [];
foreach ($goods as $good){
$goods_cate[] = $good->cate;
}
$goods_cate = array_unique($goods_cate);
$goods_cate = array_merge($goods_cate);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>商城首页</title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/shop.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<!--logo+搜索框+快捷入口区-->
<div class="logo">
<img src="static/images/logo.png" alt="">
<input type="search" id="search"><label for="search">搜索</label>
<a href="">免费入驻</a>
</div>
<!--轮播图-->
<div class="slider">
<nav>
<h3>所有产品分类 <span class="iconfont icon-liebiao"></span></h3>
<div>
<a href="">企业软件</a>
<a href="">微信推广</a>
<a href="">QQ推广</a>
<a href="">公众号推广</a>
<a href="">海客软件</a>
<a href="">网络推广</a>
<a href="">SEO软件</a>
</div>
<div>
<a href="">企业软件</a>
<a href="">微信推广</a>
<a href="">QQ推广</a>
<a href="">公众号推广</a>
<a href="">海客软件</a>
<a href="">网络推广</a>
<a href="">SEO软件</a>
</div>
<div>
<a href="">企业软件</a>
<a href="">微信推广</a>
<a href="">QQ推广</a>
<a href="">公众号推广</a>
<a href="">海客软件</a>
<a href="">网络推广</a>
<a href="">SEO软件</a>
</div>
</nav>
<div>
<div>
<a href="" class="active">首页</a>
<a href="">3C</a>
<a href="">生活用品</a><sup class="badge">新</sup>
<a href="">名字名画</a>
</div>
<img src="static/images/4.jpg" alt="" width="900" height="398">
</div>
</div>
<!--手机交易区-->
<div class="title">
<span><?=$goods_cate[0]?></span>
</div>
<div class="second-hand">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<?php
$good_img = [];
$good_name = [];
$good_price = [];
$good_id = [];
foreach ($goods as $good){
if ($good->cate == $goods_cate[0]){
$good_img[] = $good->image;
$good_name[] = $good->name;
$good_price[] = $good->price;
$good_id[] = $good->good_id;
}
}
for ($i=0;$i<4;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=0;$i<4;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
echo '</div>';
}
for ($i=4;$i<8;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=4;$i<8;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[0] . '</span></a></div>';
echo '</div>';
}
?>
<div>
<a href=""><img src="static/images/ad/1.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/2.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/3.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/4.png" alt="" width="180" height="112"></a>
<a href=""><img src="static/images/ad/image.png" alt="" width="393" height="56"></a>
<a href=""><img src="static/images/ad/ad2.jpg" alt="" width="393" height="56"></a>
</div>
</div>
<!--电脑交易区1-->
<div class="title">
<span><?=$goods_cate[1]?></span>
</div>
<div class="mirror">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<?php
$good_img = [];
$good_name = [];
$good_price = [];
$good_id = [];
foreach ($goods as $good){
if ($good->cate == $goods_cate[1]){
$good_img[] = $good->image;
$good_name[] = $good->name;
$good_price[] = $good->price;
$good_id[] = $good->good_id;
}
}
for ($i=0;$i<6;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=0;$i<6;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
echo '</div>';
}
for ($i=6;$i<12;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=6;$i<12;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
echo '</div>';
}
?>
</div>
<!--电脑交易区2-->
<div class="title">
<span><?=$goods_cate[1]?></span>
</div>
<div class="mirror">
<div>
<a href="">抢好货</a>
<span>0低价, 便捷,安全,快速</span>
</div>
<div>
<span>热门分类</span>
<a href="">美女写真</a>
<a href="">日本美女</a>
<a href="">美国美女</a>
<a href="">国内美女</a>
<a href="">AV美女</a>
</div>
<?php
$good_img = [];
$good_name = [];
$good_price = [];
$good_id = [];
foreach ($goods as $good){
if ($good->cate == $goods_cate[1]){
$good_img[] = $good->image;
$good_name[] = $good->name;
$good_price[] = $good->price;
$good_id[] = $good->good_id;
}
}
for ($i=0;$i<6;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=0;$i<6;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
echo '</div>';
}
for ($i=6;$i<12;$i++){
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '"><img src="static/images/' . $good_img[$i] . '" alt="" width="176" height="120"></a>';
}
for ($i=6;$i<12;$i++){
echo '<div class="detail">';
echo '<a href="shop_content.php?good_id=' . $good_id[$i] . '">' . mb_substr($good_name[$i], 0, 30, "utf-8") . '...</a>';
echo '<div><a href="shop_content.php?good_id=' . $good_id[$i] . '"><span>¥ ' . $good_price[$i] . '</span><span>' . $goods_cate[1] . '</span></a></div>';
echo '</div>';
}
?>
</div>
<?php
require __DIR__ . '/footer.php';
?>
shop_content.php
<?php
require __DIR__ . '/common.php';
$good_id = $_GET['good_id'];
$good = $controller->find('good', 'view', 'goods', '*', 'good_id=' . $good_id);
$goods = $controller->select('good','view','goods','*','cate="' . $good->cate . '"' ,'sales DESC',5);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?=$good->name?></title>
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="static/css/shop-content.css">
</head>
<body>
<?php
require __DIR__ . '/header.php';
?>
<!--logo+搜索框+快捷入口区-->
<div class="logo">
<img src="static/images/logo.png" alt="">
<input type="search" id="search"><label for="search">搜索</label>
<a href="">免费入驻</a>
</div>
<main>
<!--导航-->
<nav>
<h3>所有产品分类 <span class="iconfont icon-liebiao"></span></h3>
<a href="" class="active">首页</a>
<a href="">3C</a>
<a href="">生活用品</a>
<a href="">名字名画</a>
</nav>
<!-- 商品展示-->
<div class="goods">
<div class="top-nav">
<a href="">首页</a>->>
<a href="">3C数码</a>->>
<a href=""><?=$good->cate?></a>->>
</div>
<img src="static/images/<?=$good->image?>" alt="">
<h2><?=$good->name?></h2>
<p>本站特惠: <span>¥<?=$good->price?></span></p>
<p>
销量: <span><?=$good->sales?></span> |
累积评价: <span><?=$good->judge?></span> |
好评率: <span><?=$good->good_ratings?>%</span>
</p>
<p>
<label for="num">购买数量:</label><input type="number" id="num" value="1">
</p>
<div>
<button>立即购买</button>
<button><i class="iconfont icon-icon_tianjia"></i>加入购物车</button>
</div>
<div>
<span><i class="iconfont icon-zhanghaoquanxianguanli"></i>本站保障</span>
<span><i class="iconfont icon-icon_safety"></i>企业认证</span>
<span><i class="iconfont icon-tianshenpi"></i>退款承诺</span>
<span><i class="iconfont icon-kuaisubianpai"></i>免费换货</span>
</div>
</div>
<!-- 商品详情-->
<div class="detail">
<aside>
<div><span>商品推荐</span><span>其它热销</span></div>
<?php
foreach ($goods as $gd){
echo '<div>';
echo '<a href="shop_content.php?good_id=' . $gd->good_id . '"><img src="static/images/' . $gd->image . '" alt=""></a>';
echo '<a href="">' . mb_substr($gd->name, 0, 20, "utf-8") . '...</a>';
echo '<div><span>热销:' . $gd->sales . '</span><span>¥' . $gd->price . '</span></div>';
echo '</div>';
}
?>
</aside>
<article>
<div class="nav">
<a href="">商品详情</a>
<a href="">案例/演示</a>
<a href="">常见问题</a>
<a href="">累计评价</a>
<a href="">产品咨询</a>
</div>
<div class="content">
<?=$good->detail?>
</div>
<div class="comment">
<h3>网页评论</h3>
<img src="static/images/user.png" alt="" width="60">
<textarea name="" id="" cols="30" rows="10"></textarea>
<button>发表评论</button>
</div>
<!-- 最新评论-->
<div>
<h3>最新评论</h3>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
<div>
<img src="static/images/user.png" alt="" width="60" height="60">
<span>用户昵称</span>
<span>留言内容</span>
<div>
<span>2019-12-12 15:34:23发表</span>
<span><i class="iconfont icon-dianzan"></i>回复</span>
</div>
</div>
</div>
</article>
</div>
</main>
<?php
require __DIR__ . '/footer.php';
?>
很多地方写的还是很繁琐,视图类没有起到真正渲染模板的作用,仅用于返回数据,还是得加强学习。