返回前台模块的实现...登陆

前台模块的实现

1Pong2019-05-31 16:57:52344

通过本章的学习,完成了前台模块。学完本章后,整个企业站的项目实战课程已结课,通过本套实践课程的学习,已经能过通过搭建后台数据库,并利用tp5.1作为后台框架,通过layui作为前端框架,实现网站的前台展示和后台界面管理。代码如下:

控制器类:

index.php:

<?php
namespace app\index\controller;

use app\admin\model\news\NewsModel;
use app\admin\model\product\ProductModel;
use app\admin\model\slide\SlideModel;
use app\admin\model\system\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;
        // 查询新上花魁
        $NewProduct = $product->where('sort','2')->limit(1)->select()->toArray();
        $this->view->NewProduct = $NewProduct;

        // 查询最新资讯
        $new = new NewsModel();
        $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 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();
    }

    public function ConPro()
    {
        // 获取产品id
        $ProId = Request::param('id');
        $product = ProductModel::get($ProId);
        $this->view->product=$product;
        // 渲染模板
        return $this->fetch();
    }

}

效果图:

QQ截图20190531165249.png

QQ截图20190531165301.png

QQ截图20190531165311.png

QQ截图20190531165322.png

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送