首页 > 其他 > 详细

TP5指定讲师页面文章上下篇

时间:2019-10-16 15:04:58      阅读:70      评论:0      收藏:0      [点我收藏+]

控制器代码 

// 查询上下篇
        $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}}

 

TP5指定讲师页面文章上下篇

原文:https://www.cnblogs.com/init-007/p/11685152.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!