zoukankan      html  css  js  c++  java
  • TP5指定讲师页面文章上下篇

    控制器代码 

    // 查询上下篇
            $courseIds = model('course')
                ->where([
                    'isdel' => 0,
                    'teacherid' => $teacher['id'],
                    'ispublic' => 1
                ])
                ->order('sort desc')
                ->order('view desc')
                ->column('id');
            $cidKey = array_search($cid, $courseIds);
            $preCourseId = array_key_exists($cidKey+1, $courseIds) ? $courseIds[($cidKey +1)] : false;
            $nexCourseId = array_key_exists($cidKey-1, $courseIds) ? $courseIds[($cidKey -1)] : false;
    
            $this->assign([
                'course' => $course,
                'preCourseId' => $preCourseId,
                'nexCourseId' => $nexCourseId,
                'model' => new CourseModel
            ]);

     模板代码

    {{if condition="$preCourseId !== false"}}
    <div>
         <span class="font-bold">上一篇:</span><a href="{{:url('index/teacher/cindex', ['cid' => $preCourseId])}}">{{$model->get($preCourseId)['title']}}</a>
    </div>
    {{/if}}
    {{if condition="$nexCourseId !== false"}}
    <div>
        <span class="font-bold">下一篇:</span><a href="{{:url('index/teacher/cindex', ['cid' => $nexCourseId])}}">{{$model->get($nexCourseId)['title']}}</a>
    </div>
    {{/if}}
  • 相关阅读:
    敏捷开发方法综述
    RBAC权限控制系统
    Thinkphp 视图模型
    Thinkphp 缓存和静态缓存局部缓存设置
    Thinkphp路由使用
    Thinkphp自定义标签
    异步处理那些事
    Thinkphp 关联模型
    Thinkphp 3.1. 3 ueditor 1.4.3 添加水印
    数据库组合
  • 原文地址:https://www.cnblogs.com/init-007/p/11685152.html
Copyright © 2011-2022 走看看