亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

網(wǎng)站開發(fā)前臺(tái)模塊控制器練習(xí)代碼

Original 2019-05-07 21:48:42 378
abstract:網(wǎng)站開發(fā)前臺(tái)模塊控制器,可以實(shí)例化后臺(tái)的模型,在前臺(tái)查詢循環(huán)并顯示數(shù)據(jù)庫中的代碼即可,練習(xí)代碼如下:<?php namespace app\index\controller; use app\admin\model\NewsModel; use app\admin\model\ProductModel; use app\admin\model\Slid

網(wǎng)站開發(fā)前臺(tái)模塊控制器,可以實(shí)例化后臺(tái)的模型,在前臺(tái)查詢循環(huán)并顯示數(shù)據(jù)庫中的代碼即可,練習(xí)代碼如下:

<?php
namespace app\index\controller;
use app\admin\model\NewsModel;
use app\admin\model\ProductModel;
use app\admin\model\SlideModel;
use app\admin\model\SystemModel;
use think\Controller;
use think\facade\Request;

class Index extends Controller
{
    //渲染網(wǎng)站首頁
    public function index()
    {
        //實(shí)例化查詢輪播圖
        $slide = new SlideModel();
        //查詢縮略圖
        $slides = $slide->select()    //查詢
            ->toArray();              //轉(zhuǎn)化成數(shù)組賦值
        $this->view->slides=$slides;

        //實(shí)例化并查詢頭牌
        $product = new ProductModel();
        $products = $product->where('sort','2')   //查詢條件
            ->select()             //查詢
            ->toArray();           //轉(zhuǎn)換
        $this->view->products = $products;
        //實(shí)例化并查詢花魁
        $NewsProduct = $product->where('sort','4')
            ->select()
            ->toArray();
        $this->view->NewsProduct = $NewsProduct;

        //實(shí)例化并查詢最新資訊
        $new= new NewsModel();
        $news = $new->limit(4)->select()->toArray();
        $this->view->news = $news;
        return $this->fetch();
    }

    //渲染關(guān)于我們
    public function about()
    {
        $system = new SystemModel();
        $systems = $system->select()->toArray();
        $this->view->systems = $systems;
        return $this->fetch();
    }

    //渲染產(chǎn)品展示
    public function product()
    {
        $product = new ProductModel();
        $products = $product->order('id','desc')   //id排序
            ->paginate(2);                //2條分頁
        $this->view->products = $products;
        return $this->fetch();
    }

    //渲染產(chǎn)品顯示頁
    public function ConPro()
    {
        //獲取傳遞過來的ID
        $ProID = Request::param('id');
        $product = ProductModel::get($ProID);
        $this->view->product = $product;
        return $this->fetch();
    }

    //渲染新聞?wù)故?    public function news()
    {
        //實(shí)例化
        $new = new NewsModel();
        $news = $new->order('id','desc')
            ->paginate(4);
        $this->view->news = $news;

        //熱門新聞
        $hotNew = $new->limit(1)->select()->toArray();
        $this->view->hotNew = $hotNew;

        //最新發(fā)布
        $newNew = $new->limit(5)->select()->toArray();
        $this->view->newNew = $newNew;
        return $this->fetch();
    }

    //新聞詳情
    public function ConNew()
    {
        $newId = Request::get('id');
        //通過ID查詢對應(yīng)的新聞詳細(xì)
        $new = NewsModel::get($newId);
        $this->view->new =$new;

        //熱門新聞
        $hotNews = $new->limit(1)->select()->toArray();
        $this->view->hotNews = $hotNews;

        //最新發(fā)布
        $newNew = $new->limit(5)->select()->toArray();
        $this->view->newNew = $newNew;
        return $this->fetch();

        //渲染模板
        return $this->fetch();
    }

}


Correcting teacher:查無此人Correction time:2019-05-08 09:38:05
Teacher's summary:完成的不錯(cuò)。想學(xué)會(huì)框架,就要學(xué)框架的操作方法。繼續(xù)加油。

Release Notes

Popular Entries