完成企业官网前后台小案例

Original 2019-07-23 01:48:39 414
abstract:<?php namespace app\index\controller; use app\admin\model\NewModel; use app\admin\model\ProductModel; use app\admin\model\SlideModel; use app\admin\model\SystemModel; use&n

2019-07-23_013922.jpg2019-07-23_014007.jpg2019-07-23_014050.jpg2019-07-23_014134.jpg2019-07-23_013823.jpg

<?php
namespace app\index\controller;
use app\admin\model\NewModel;
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
{
    public function index()
    {
//        轮播图查询
        $slide= new SlideModel();
        $slides=$slide->select()->toArray();
        $this->view->slides=$slides;

//        最新产品查询

        $product=new ProductModel();
        $products=$product->where('sort','1')->select()->toArray();
        $this->view->products = $products;

//        新上花魁
        $NewProducts=$product->where('sort','2')->limit(1)->select()->toArray();
        $this->view->NewProducts = $NewProducts;

//        最新资讯

        $new = new NewModel();
        $news=$new->limit(4)->select()->toArray();
        $this->view->news=$news;
        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 news()
    {
        $new = new NewModel();
        $news=$new->order('id','desc')->paginate(4);
        $this->view->news=$news;
//        新闻列表

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


        $newNews=$new->limit(6)->select()->toArray();
        $this->view->newNews=$newNews;
        return $this->fetch();
    }

    public function ConNew()
    {
        $newId=Request::param('id');
        $new=NewModel::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();
    }

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


经过本章节的练习,熟练掌握了thinkphp前端渲染技术。强大的框架大大方便了平时项目开发效率。后续不断加强练习让更加巩固php开发技能

Correcting teacher:查无此人Correction time:2019-07-23 09:56:32
Teacher's summary:完成的不错。多看thinkphp的文档,多练习功能,很快就能上手。继续加油。

Release Notes

Popular Entries