前台渲染实现

Original 2018-12-30 17:38:30 241
abstract:<?php namespace app\index\controller; use app\admin\model\NewsModel; use app\admin\model\ProductModel; use app\admin\model\SlideModel; use app\admin\model\SortModel; use&n
<?php
namespace app\index\controller;

use app\admin\model\NewsModel;
use app\admin\model\ProductModel;
use app\admin\model\SlideModel;
use app\admin\model\SortModel;
use app\admin\model\SystemModel;
use think\Controller;
use think\facade\Request;


class Index extends Controller
{
    public function index()
    {
        //查询轮播图
        $slide = new SlideModel();
        $slides = $slide->select()->toArray();
        $this->view->slides=$slides;

        //查看爆款产品
        $product = new ProductModel();
        $products = $product->limit(4)->where('sort',3)->select()->toArray();
        $this->view->products=$products;

        //查看新款产品
        $NewProducts = $product->limit(1)->where('sort',2)->select()->toArray();
        $this->view->NewProducts=$NewProducts;

        //查看新闻资讯
        $news = new NewsModel();
        $new = $news->limit(2)->select()->toArray();
        $this->view->new=$new;
        //渲染首页模版
        return $this->fetch();
    }

    public function about()
    {
        $system = new SystemModel();
        $systems = $system->select()->toArray();
        $this->view->systems=$systems;
        //渲染关于我们模版
        return $this->fetch();
    }



    public function product()
    {
        $product = new ProductModel();
        $products = $product->order('id','desc')->paginate(4);
        $this->view->products=$products;

        //渲染关于我们模版
        return $this->fetch();
    }

    public function ConPro()
    {
        $ProId = Request::param('id');
        $product = ProductModel::get($ProId);
        $this->view->product=$product;

        return $this->fetch();
    }


    public function news()
    {
        // 实例化模型
        $new = new NewsModel();
        // 查询数据按照id的顺序查询并且每页四条数据
        $news = $new->order('id','desc')->paginate(4);
        // 给模板继续赋值
        $this->view->news=$news;

        $hotNew = $new->limit(1)->select()->toArray();
        $this->view->hotNews = $hotNew;

        $newNews = $new->limit(6)->select()->toArray();
        $this->view->newNews=$newNews;
        // 渲染首页模板
        return $this->fetch();
    }

    public function ConNew()
    {
        $newId = Request::param('id');
        // 通过id查询对应的新闻详细
        $new = NewsModel::get($newId);
        $this->view->new= $new;

        $hotNew = $new->limit(1)->select()->toArray();
        $this->view->hotNews = $hotNew;

        $newNews = $new->limit(6)->select()->toArray();
        $this->view->newNews=$newNews;
        // 渲染首页模板
        return $this->fetch();
    }





}


Correcting teacher:天蓬老师Correction time:2018-12-30 17:52:07
Teacher's summary:服务器端来渲染前端页面,现在仍然是主流技术之一,不仅简便,还易于维护,好好学

Release Notes

Popular Entries