前台模块功能代码

原创 2018-11-12 23:45:41 324
摘要:<?phpnamespace app\index\controller;use app\model\SlideModel;use app\model\ProductModel;use app\model\News as NewsModel;use app\model\SystemModel;use think\facade\Request;class Index extends \think
<?php
namespace app\index\controller;
use app\model\SlideModel;
use app\model\ProductModel;
use app\model\News as NewsModel;
use app\model\SystemModel;
use think\facade\Request;

class Index extends \think\Controller
{
//前台模板首页
public function index()
    {
//渲染轮播图
$slides = SlideModel::all();
$this->assign('slides',$slides);

//渲染产品 头牌人选
$products = ProductModel::where('sort',3)->select();
$this->assign('products',$products);

//渲染产品 新上花魁
$newProducts = ProductModel::where('sort',2)->select();
$this->assign('newProducts',$newProducts);

//渲染最新资讯
$news = NewsModel::all();
$this->assign('news',$news);
return $this->fetch();
}

//前台模板关于我们
public function about(){
$system = SystemModel::find();
$this->assign('system',$system);
return $this->fetch();
}


//前台模板产品展示
public function product(){
$res = ProductModel::order('id','asc')->paginate(3);
$this->assign('res',$res);
return $this->fetch();
}

//产品详情
public function contentPro(){
//获取数据id
$id = Request::param('id');
$res = ProductModel::get($id);
$this->assign('res',$res);
return $this->fetch();

}

//前台模板新闻中心
public function news(){
$res = NewsModel::order('id','asc')->paginate(3);
$this->assign('res',$res);

//热门新闻
$hotNew =  NewsModel::limit(1)->select();
$this->assign('hotNew',$hotNew);

//最新发布
$news =  NewsModel::limit(2)->select();
$this->assign('news',$news);
return $this->fetch();
}

//新闻详情
public function contentNew(){
//获取数据id
$id = Request::param('id');
$res = NewsModel::get($id);
$this->assign('res',$res);

//热门新闻
$hotNew =  NewsModel::limit(1)->select();
$this->assign('hotNew',$hotNew);

//最新发布
$news =  NewsModel::limit(2)->select();
$this->assign('news',$news);
return $this->fetch();
}
}


批改老师:韦小宝批改时间:2018-11-13 09:13:02
老师总结:代码部分很完整!但是缺少总结!下次的代码记得带上自己的总结以及代码的高亮!课后多多练习!加油吧!!!

发布手记

热门词条