abstrakt:<?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\
<?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 = SlideModel::field('pic,desc')->all(); // 模板賦值 $this->assign('slide',$slide); // 獲取產(chǎn)品信息 $products = ProductModel::where('cate_id',1)->all(); $this->assign('products',$products); // 獲取最新的產(chǎn)品信息 $newPro = ProductModel::order('cate_id','desc')->find()->toArray(); $this->assign('newPro',$newPro); // 查詢最新新聞 $new = NewsModel::order('id','desc')->limit(2)->all(); $this->assign('news',$new); // 渲染模板 return $this->fetch(); } // 關(guān)于我們 public function about() { // 獲取系統(tǒng)設(shè)置信息 $systems = SystemModel::where('id',1)->find()->toArray(); // 模板賦值 $this->assign('systems',$systems); // 渲染頁面 return $this->fetch(); } // 產(chǎn)品信息 public function product() { // 獲取產(chǎn)品信息 $products = ProductModel::order('id','desc')->paginate(2); // 模板賦值 $this->assign('products',$products); // 模板渲染 return $this->fetch(); } // 獲取產(chǎn)品詳細(xì) public function Conpro() { // 獲取ID $pro_id = Request::param('id'); // 獲取產(chǎn)品信息 $product = ProductModel::find($pro_id); // 模板賦值 $this->assign('pro',$product); // 模板渲染 return $this->fetch(); } // 新聞中心 public function news() { // 獲取信息列表 $news = NewsModel::order('id','desc')->paginate(3); // 模板賦值 $this->assign('news',$news); // 查詢最新的一條,為熱門新聞 $hostNew = NewsModel::order('id','desc')->find(); $this->assign('hostNew',$hostNew); // 渲染模板 return $this->fetch(); } // 獲取新聞詳細(xì) public function Connew() { // 獲取新聞ID $new_id = Request::param('id'); // 獲取新聞信息 $news = NewsModel::get($new_id)->toArray(); // 模板賦值 $this->assign('news',$news); // 查詢最新的一條,為熱門新聞 $hostNew = NewsModel::order('id','desc')->find(); $this->assign('hostNew',$hostNew); $newsd = NewsModel::order('id','desc')->limit(3)->all(); $this->assign('newsd',$newsd); // 模板渲染 return $this->fetch(); } }
課程總結(jié):本課程基本使用了TP5.1的操作功能,模型,視圖,控制器,分頁,增刪查改,公共函數(shù)庫等,涵蓋了數(shù)據(jù)的基本操作。
Korrigierender Lehrer:天蓬老師Korrekturzeit:2019-04-28 08:47:02
Zusammenfassung des Lehrers:一個(gè)框架的核心功能 差不多就是這些了, 基本上可以創(chuàng)建出一個(gè)小型項(xiàng)目了