摘要:view\index\news.html代码<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport
view\index\news.html代码
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>丽春院 — 新闻中心</title>
{include file="public/style"}
</head>
<body>
<div id="page">
{include file="public/head"}
<div id="body">
<div class="header">
<div>
<h1 style="color: #6E6E6E; font-family: YouYuan; font-weight: bold">新闻中心</h1>
<div class="article">
<ul>
{volist name="news" id="new"}
<li>
<a href="{:url('ConNew')}?id={$new.id}" target="_blank"><img src="{:GetNewsPic($new.id)}" style="border-radius:10px; box-shadow: 0 0 0px #6E6E6E; width: 100%;height: 100%;" alt=""></a>
<h1>{$new.title}</h1>
<span style="color: #0C0C0C">{$new.time|date="Y.m.d"}</span>
<p style="color: #0C0C0C">{$new.desc}</p>
<a href="{:url('ConNew')}?id={$new.id}" target="_blank" class="more">阅读更多</a>
</li>
{/volist}
</ul>
</div>
<div class="sidebar">
<ul>
<li>
<h1>热门新闻</h1>
{volist name="hotNews" id="hotNew"}
<a href="{:url('ConNew')}?id={$hotNew.id}" target="_blank"><img src="{:GetNewsPic($hotNew.id)}" style="border-radius:10px; box-shadow: 0 0 5px #6E6E6E; width: 340px;height: 188px;" alt=""></a>
<h2>{$hotNew.title}</h2>
<span>{$hotNew.desc}</span>
{/volist}
</li>
<li>
<h1>最新发布</h1>
<ul>
{volist name="newNews" id="newNew"}
<li>
<a href="{:url('ConNew')}?id={$newNew.id}" target="_blank"><img src="{:GetNewsPic($newNew.id)}" style="border-radius:10px; box-shadow: 0 0 2px #6E6E6E; width: 60px;height: 55px;" alt=""></a>
<h2 style="font-size: 15px;">{$newNew.title}</h2>
<span>{$newNew.time|date="Y.m.d"}</span>
</li>
{/volist}
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="page">
<div>
{$news|raw}
</div>
</div>
</div>
{include file="public/foot"}
</div>
</body>
</html>view\index\con_new.html代码
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>丽春院 — 新闻详细</title>
{include file="public/style"}
</head>
<body>
<div id="page">
{include file="public/head"}
<div id="body">
<div class="header">
<div>
<h1 style="color: #6E6E6E; font-family: YouYuan; font-weight: bold">新闻详细</h1>
<div class="article">
<img src="{:GetNewsPic($new.id)}" style="border-radius:10px; box-shadow: 0 0 5px #6E6E6E; width: 560px;height: 240px;" alt="">
<div style="border-radius:10px; box-shadow: 0 0 5px #6E6E6E; background: #BDBDBD; padding: 20px;">
<h1 style=" text-align:center; color: #000;">{$new.title}</h1>
<span style="color: #0C0C0C">{$new.time|date="Y.m.d"}</span>
<p>{:htmlspecialchars_decode($new.content)}</p></div>
</div>
<div class="sidebar">
<ul>
<li>
<h1>热门新闻</h1>
{volist name="hotNews" id="hotNew"}
<a href="{:url('ConNew')}?id={$hotNew.id}" target="_blank"><img src="{:GetNewsPic($hotNew.id)}" style="border-radius:10px; box-shadow: 0 0 5px #6E6E6E; width: 340px;height: 188px;" alt=""></a>
<h2>{$hotNew.title}</h2>
<span>{$hotNew.desc}</span>
{/volist}
</li>
<li>
<h1>最新发布</h1>
<ul>
{volist name="newNews" id="newNew"}
<li>
<a href="{:url('ConNew')}?id={$newNew.id}" target="_blank"><img src="{:GetNewsPic($newNew.id)}" style="border-radius:10px; box-shadow: 0 0 2px #6E6E6E; width: 60px;height: 55px;" alt=""></a>
<h2 style="font-size: 15px;">{$newNew.title}</h2>
<span>{$newNew.time|date="Y.m.d"}</span>
</li>
{/volist}
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
{include file="public/foot"}
</div>
</body>
</html>controller\Index.php代码
<?php
namespace app\index\controller;
use think\Controller;
use think\facade\Request;
use app\admin\model\SlideModel;
use app\admin\model\ProductModel;
use app\admin\model\NewsModel;
use app\admin\model\SystemModel;
class Index extends Controller
{
public function index()
{
//查询轮播图并给模板赋值
$slide = new SlideModel();
$slides = $slide->select()->toArray();
$this->view->slides=$slides;
//查询头牌人选并给模板赋值
$product = new ProductModel();
$products = $product->where('sort',7)->select()->toArray();
$this->view->products=$products;
//查询新上花魁并给模板赋值
$NewProduct = $product->where('sort',5)->limit(1)->select()->toArray();
$this->view->NewProduct=$NewProduct;
//查询最新资讯并给模板赋值
$new = new NewsModel();
$news = $new->limit(2)->select()->toArray();
$this->view->news=$news;
//渲染首页模板
return $this->fetch();
}
public function about()
{
//查询系统设置并给模板赋值
$system = new SystemModel();
$systems = $system->select()->toArray();
$this->view->systems=$systems;
//渲染关于我们模板
return $this->fetch();
}
public function product()
{
//查询全部产品并给模板赋值
$product = new ProductModel();
$products = $product->order('id','desc')->paginate(4);
$this->view->products=$products;
//渲染产品展示模板
return $this->fetch();
}
public function ConPro()
{
//获取产品id
$ProId = Request::param('id');
//查询产品并给模板赋值
$product = ProductModel::get($ProId);
$this->view->product=$product;
//渲染产品详细页模板
return $this->fetch();
}
public function news()
{
//查询全部新闻并给模板赋值
$new = new NewsModel();
$news = $new->order('id','desc')->paginate(4);
$this->view->news=$news;
//查询热门新闻并给模板赋值
$hotNews = $new->limit(1)->select()->toArray();
$this->view->hotNews=$hotNews;
//查询最新发布新闻并给模板赋值
$newNews = $new->limit(6)->select()->toArray();
$this->view->newNews=$newNews;
//渲染新闻中心模板
return $this->fetch();
}
public function ConNew()
{
//获取新闻id
$newId = Request::param('id');
//查询新闻并给模板赋值
$new = NewsModel::get($newId);
$this->view->new=$new;
//查询热门新闻并给模板赋值
$hotNews = $new->limit(1)->select()->toArray();
$this->view->hotNews=$hotNews;
//查询最新发布新闻并给模板赋值
$newNews = $new->limit(6)->select()->toArray();
$this->view->newNews=$newNews;
//渲染新闻详细页模板
return $this->fetch();
}
}
批改老师:天蓬老师批改时间:2018-12-23 10:31:31
老师总结:作业写的不错,注释比较清晰,继续努力,加油