摘要:<?php namespace app\index\controller; use app\admin\model\NewModel; use app\admin\model\ProductModel; use app\admin\model\SlideModel; use app\admin\model\SystemModel; use&n
<?php namespace app\index\controller; use app\admin\model\NewModel; 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; // 最新產(chǎn)品查詢 $product=new ProductModel(); $products=$product->where('sort','1')->select()->toArray(); $this->view->products = $products; // 新上花魁 $NewProducts=$product->where('sort','2')->limit(1)->select()->toArray(); $this->view->NewProducts = $NewProducts; // 最新資訊 $new = new NewModel(); $news=$new->limit(4)->select()->toArray(); $this->view->news=$news; return $this->fetch(); } public function about() { // 關(guān)于我們 $system=new SystemModel(); $systems=$system->select()->toArray(); $this->view->systems=$systems; return $this->fetch(); } public function product() { // 產(chǎn)品列表 $product=new ProductModel(); $products=$product->order('id','desc')->paginate(4); $this->view->products=$products; return $this->fetch(); } public function news() { $new = new NewModel(); $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() { $newId=Request::param('id'); $new=NewModel::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() { $proId=Request::param('id'); $product=ProductModel::get($proId); $this->view->product=$product; return $this->fetch(); } }
經(jīng)過本章節(jié)的練習(xí),熟練掌握了thinkphp前端渲染技術(shù)。強(qiáng)大的框架大大方便了平時(shí)項(xiàng)目開發(fā)效率。后續(xù)不斷加強(qiáng)練習(xí)讓更加鞏固php開發(fā)技能
批改老師:查無此人批改時(shí)間:2019-07-23 09:56:32
老師總結(jié):完成的不錯(cuò)。多看thinkphp的文檔,多練習(xí)功能,很快就能上手。繼續(xù)加油。