abstrait:<?phpnamespace app\index\controller;use app\admin\model\NewsModel;use app\admin\model\ProductModel;use think\Controller;use think\Db;use think\facade\Request;class Index extends Controller{
<?php
namespace app\index\controller;
use app\admin\model\NewsModel;
use app\admin\model\ProductModel;
use think\Controller;
use think\Db;
use think\facade\Request;
class Index extends Controller
{
//渲染頁面模板
public function index()
{
//輪播圖數(shù)據(jù)
$data['banner']=Db::table('slide')->select();
//頭牌數(shù)據(jù)
$data['hot']=ProductModel::where('sort',1)->all();
//新上花魁數(shù)據(jù)
$data['flower']=ProductModel::where('sort',3)->find();
//新聞
$data['news']=NewsModel::limit(4)->all();
return $this->fetch('',$data);
}
//渲染關于我們頁面
public function about()
{
$about=Db::table('system')->find();
$this->view->about=$about;
return $this->fetch();
}
//渲染產品頁面
public function product()
{
$data['product']=ProductModel::paginate(4);
return $this->fetch('',$data);
}
//渲染新聞頁面
public function news()
{
$data=NewsModel::order('id','desc')->paginate(4);
$this->view->data=$data;
//熱門新聞
$hotNew=NewsModel::order('id','desc')->limit(1)->select();
$this->view->hotNew=$hotNew;
//最新發(fā)布
$news =NewsModel::limit(4)->select();
$this->view->news=$news;
return $this->fetch();
}
//產品詳細
public function ConPro()
{
$id = Request::param('id');
$detail = ProductModel::get($id);
$this->view->detail=$detail;
return $this->fetch();
}
//新聞詳細
public function ConNew()
{
$hotNew=NewsModel::order('id','desc')->limit(1)->select();
$this->view->hotNew=$hotNew;
//最新發(fā)布
$news =NewsModel::limit(4)->select();
$this->view->news=$news;
//新聞詳細內容
$id = Request::param('id');
$detail = NewsModel::get($id);
$this->view->detail=$detail;
return $this->fetch();
}
}
總結:通過本套課程,讓我了解了tp5框架的運行原理,以及如何使用這個框架和如何去開發(fā)一個項目。但是有的具體的使用還需多多練習項目才行
Professeur correcteur:西門大官人Temps de correction:2019-04-09 10:25:02
Résumé du professeur:孰能生巧,光看不練,一切都會歸零。加油。