前台模块的代码完成

原创 2019-01-13 20:09:13 257
摘要:<?php namespace app\index\controller; use think\Controller; use app\admin\model\slide as SlideModel; use app\admin\model\product as ProductModel; use a
<?php
namespace app\index\controller;

use think\Controller;
use app\admin\model\slide as SlideModel;
use app\admin\model\product as ProductModel;
use app\admin\model\news as NewsModel;
use app\admin\model\system as SystemModel;
use think\facade\Request;

class Index extends Controller
{
    public function index()
    {
        //获取需要的数据
        $slides = SlideModel::all();
        $products = ProductModel::limit(4)->where('sort','1')->select();
        $system = SystemModel::limit(1)->get(1);
        $news = NewsModel::limit(2)->select()->toArray();
        $NewsProduct = ProductModel::field('id,sort')->limit(1)->where('sort','4')->find();
        //传递给前端
        $this->assign('slides',$slides);
        $this->assign('products',$products);
        $this->assign('system',$system);
        $this->assign('news',$news);
        $this->assign('NewsProduct',$NewsProduct);
        return $this->fetch();
    }

    public function about()
    {
        $system = SystemModel::get(1);
        $this->assign('system',$system);
        return $this->fetch();
    }

    public function news()
    {
        $News = NewsModel::select()->toArray();
        $this->assign('News',$News);
        return $this->fetch();
    }

    public function product()
    {
        $products = ProductModel::field('id,title,desc,content,sort')->all();
        $this->assign('products',$products);
        return $this->fetch();
    }

    public function conPro()
    {
        $id = Request::param();
        $product = ProductModel::get($id);
        $this->assign('product',$product);
        return $this->fetch();
    }

    public function conNew()
    {
        $id = Request::param();
        $News = NewsModel::get($id);
        $this->assign('News',$News);
        return $this->fetch();
    }

}


批改老师:韦小宝批改时间:2019-01-14 09:52:05
老师总结:完成的很不错 整个项目应该写完了吧 可以考虑写个自己的博客来练手哦 不看教程 完全自己写

发布手记

热门词条