前台模板渲染及代码

原创 2019-01-07 16:57:22 364
摘要:<?php namespace app\index\controller; use app\admin\model\ProductModel; use app\admin\model\SlideModel; use app\admin\model\NewsModel; use app\admin\model\SystemModel; use&
<?php
namespace app\index\controller;
use app\admin\model\ProductModel;
use app\admin\model\SlideModel;
use app\admin\model\NewsModel;
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','9')->select()->toArray();
        $this->view->products = $products;
        //查询新上

        $NewProduct = $product->where('sort','12')->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();
    }
}
/*******************************************************************/
<!doctype html>
<!--前台主页-->
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>黑水国际</title>
    {include file="public/style"}
    {include file="public/head"}
</head>
<body>
<div id="page">
    <div id="body" class="home">
        <div class="demo">
            <a class="control prev"></a><a class="control next abs"></a><!--自定义按钮,移动端可不写-->
            <div class="slider"><!--主体结构,请用此类名调用插件,此类名可自定义-->
                <ul>
                    {volist name="slides" id="slide"}
                    <li><a href=""><img src="{$slide.pic}" alt="{$slide.desc}"/></a></li>
                    {/volist}
                </ul>
            </div>
        </div>
        <div class="header">
            <div>
                <h3 style="margin-top: 50px">新上精品</h3>
                <ul>
                    {volist name="products" id="product"}
                    <li>
                        <a href=""><img src="{:GetProPic($product.id)}"
                                        style=" width: 260px;height: 160px;" alt=""></a>
                    </li>
                    {/volist}
                </ul>
            </div>
        </div>
        <div class="body">
            <div>
                <h1>丽春院百年老店</h1>
                <p>为看官提供更养眼、更多样、更直观的感觉体验!</p>
            </div>
        </div>
        <div class="footer">
            <div>
                <ul>
                    <li>
                        <h1>新上花魁</h1>
                        {volist name="NewProduct" id="NewProduct"}
                        <a href=" ">
                            <img src="{:GetProPic($NewProduct.id)}"
                             style="border-radius:10px; box-shadow: 0 0 10px #eaeaea;   border:1px solid #E9E7E7;width: 300px;height: 300px;"
                             alt=""></a>
                        {/volist}
                    </li>
                    <li>
                        <h1>最新资讯</h1>
                        <ul>
                            {volist name="news" id="new"}
                            <li>
                                <a href=""><img src="{:GetNewsPic($new.id)}"
                                style="border-radius:10px; box-shadow: 0 0 10px #6E6E6E;   width: 100px;height: 95px;"
                                alt=""></a>
                                <h1>{$new.title}</h1>
                                <span>{$new.time|date="Y-m-d"}</span>
                                <a href="blog.php" class="more">了解更多</a>
                            </li>
                            {/volist}
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    {include file="public/foot"}
</div>
    <script>
    $(".slider").YuxiSlider({
        width: 1900, //容器宽度
        height: 450, //容器高度
        control: $('.control'), //绑定控制按钮
        during: 4000, //间隔4秒自动滑动
        speed: 800, //移动速度0.8秒
        mousewheel: true, //是否开启鼠标滚轮控制
        direkey: true //是否开启左右箭头方向控制
    });
</script>
</body>
</html>


批改老师:灭绝师太批改时间:2019-01-07 17:27:14
老师总结:学习进度保持的不错,希望学过的知识点都有好好掌握,必要的的地方敲上备注,便于修改和测试

发布手记

热门词条