完成了前台模块、首页、关于我们、新闻、产品从后台数据库中读取。
<?php namespace app\index\controller; use app\admin\model\NewsModel; use app\admin\model\ProductModel; use app\admin\model\SlideModel; use app\admin\model\SystemModel; use think\Controller; use think\facade\Request; 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','1')->select()->toArray(); $this->view->products=$products; //新产品 $productnew = $product->where('sort','4')->limit(1)->select()->toArray(); $this->view->productnew=$productnew; //最新咨询 $new = new NewsModel(); $news=$new->limit(4)->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(3); $this->view->products=$products; return $this->fetch(); } public function news() { $new = new NewsModel(); $news = $new->order('id','desc')->paginate(4); $this->view->news=$news; $hotNew= $new->limit(1)->select()->toArray(); $this->view->hotNew=$hotNew; $newNews = $new->limit(6)->select()->toArray(); $this->view->newNews=$newNews; return $this->fetch(); } public function ConPro() { $ProId = Request::get('id'); $product = ProductModel::get($ProId); $this->view->product=$product; 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(); } }