abstract:<?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()
{
//轮播图数据
$data['banner']=Db::table('slide')->select();
//头牌数据
$data['hot']=ProductModel::where('sort',1)->all();
//新上花魁数据
$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;
//最新发布
$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;
//最新发布
$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框架的运行原理,以及如何使用这个框架和如何去开发一个项目。但是有的具体的使用还需多多练习项目才行
Correcting teacher:西门大官人Correction time:2019-04-09 10:25:02
Teacher's summary:孰能生巧,光看不练,一切都会归零。加油。