摘要:<?php namespace app\index\controller; use app\admin\model\NewsModel; use app\admin\model\ProductModel; use app\admin\model\SystemModel; use think\Controller; use thin
<?php
namespace app\index\controller;
use app\admin\model\NewsModel;
use app\admin\model\ProductModel;
use app\admin\model\SystemModel;
use think\Controller;
use think\facade\Request;
class Index extends Controller
{
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 news()
{
// 实例化模型
$new = new NewsModel();
// 查询数据按照id的顺序查询并且每页四条数据
$news = $new->order('id','desc')->paginate(4);
// 赋值
$this->view->news=$news;
$hotNew = $new->limit(1)->select()->toArray();
$this->view->hotNews = $hotNew;
$newNews = $new->limit(6)->select()->toArray();
$this->view->newNews=$newNews;
// 渲染首页模板
return $this->fetch();
}
public function ConNew()
{
$newId = Request::param('id');
// 查询对应的新闻详细
$new = NewsModel::get($newId);
$this->view->new= $new;
$hotNew = $new->limit(1)->select()->toArray();
$this->view->hotNews = $hotNew;
$newNews = $new->limit(6)->select()->toArray();
$this->view->newNews=$newNews;
// 首页模板
return $this->fetch();
}
public function ConPro()
{
// 获取产品id
$ProId = Request::param('id');
$product = ProductModel::get($ProId);
$this->view->product=$product;
// 渲染首页模板
return $this->fetch();
}
}
批改老师:查无此人批改时间:2019-06-14 14:20:06
老师总结:完成的不错。php的框架多学几款,对以后工作有帮助。继续加油