thinkphp5项目--个人博客(六)

项目地址

fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlog

一、频道推荐

控制器

 <?php
namespace app\index\controller; use app\index\controller\Base;
class Article extends Base
{
public function index()
{
$arid=input('arid');
$articleres=db('article')->find($arid);
//访问一次这个方法,说明文章被访问一次,让文章的click字段值加1
db('article')->where('id','=',$arid)->setInc('click');
$cateres=db('cate')->find($articleres['cateid']); //推荐
$recres=db('article')->where(array('cateid'=>$cateres['id'],'state'=>1))->limit(8)->select();
$this->assign(array(
'articleres'=>$articleres,
'cateres'=>$cateres,
'recres'=>$recres,
)); return view();
}
}

视图

                 <!--频道推荐-->
<div class="hotsnew">
<div class="til"><h4>频道推荐</h4></div>
<ul>
{volist name='recres' id='value' }
<li>
<div class="tu">
<a href='{:url('article/index',array('arid'=>$value.id))}' target="_blank">
<img src="{if condition="$value['pic'] neq '' "}__IMG__{$value.pic} {else /}__PUBLIC__/images/error.png{/if} " alt="{$value.title}"/>
</a>
</div>
<p><a href='{:url('article/index',array('arid'=>$value.id))}'>{$value.title}</a></p>
</li>
{/volist} </ul>
</div>

二、右侧的热门点击和推荐阅读

控制器,这里在Base控制器,因为右边这部分是公共部分

 <?php
namespace app\index\controller; use think\Controller;
use think\Db;
class Base extends Controller
{
public function _initialize()
{
//得到栏目数据,并且分配
$cates = Db::name('cate')->order('id asc')->select();
$this->assign('cates',$cates); //执行处理右边的热门点击和推荐阅读
$this->right();
} //处理右边的热门点击和推荐阅读
public function right(){
//热门点击
$clicks=db('article')->order('click desc')->limit(4)->select();
//推荐
$recs=db('article')->where('state','=',1)->order('click desc')->limit(4)->select();
$this->assign(array(
'clicks'=>$clicks,
'recs'=>$recs,
));
} }

视图

            热门点击
{volist name='clicks' id='value'}
<li class="hm-t-item hm-t-item-img"><a data-pos="0" title="{$value.title}" target="_blank" href="{:url('article/index',array('arid'=>$value['id']))}" class="hm-t-img-title" style="visibility: visible;"><span>{$value.title}</span></a></li>
{/volist} 推荐阅读
{volist name='recs' id='value'}
<li class="hm-t-item hm-t-item-img"><a style="visibility: visible;" class="hm-t-img-title" href="{:url('article/index',array('arid'=>$value['id']))}" target="_blank" title="{$value.title}" data-pos="0"><span>{$value.title}</span></a></li>
{/volist}

三、公共部分的模块,方法写在公共控制器里面

thinkphp5项目--个人博客(六)的更多相关文章

  1. thinkphp5项目--个人博客(五)

    thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  2. thinkphp5项目--个人博客(一)

    thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  3. thinkphp5项目--个人博客(八)

    thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  4. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. thinkphp5项目--个人博客(三)

    thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. Do-Now—团队 冲刺博客六

    Do-Now-团队 冲刺博客六 作者:仇夏 前言 终于从四级的考试中解脱了(不过我觉得可能凉凉,呵呵),我们的APP制作也迎来了最后的两天. 自己觉得自己其实没有干成什么事情,代码什么的大都是队友们写 ...

  9. 2015-2016-2 《Java程序设计》项目小组博客

    2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...

随机推荐

  1. 基于ORA-12170 TNS 连接超时解决办法详解

    转自原文 基于ORA-12170 TNS 连接超时解决办法详解 1.开始----程序-----Oracle------配置和移植工具-----Net Manager----本地----服务命名---o ...

  2. android开发面试题

    找了将近两个星期的工作,面试了5家公司,罗列一下笔试或者面试时的问题,祝大家好运 1,handler机制 答:handler执行机制:1).在主线程中创建handler 2).子线程中借助主线程的ha ...

  3. java文件对照工具

    今天想比較一下两个java文件.这两个文件是本地的. 就在网上下载了一个对照工具(破解版)认为挺好用的对于不同的地方有高亮显示. 就给大家分享一下.软件名叫:beyond compare 软件下载地址 ...

  4. poj2528 Mayor&#39;s posters(线段树,离散化)

    离散化的思想: 对于这样的数据 (3,10000). (9,1000000). (5.100000), (1,1000). (7,1000000) 我们能够将其处理为 (2,7). (5,9). (3 ...

  5. Android学习路线(十三)Activity生命周期——暂停和恢复(Pausing and Resuming )一个Activity

    在正常使用应用的过程中.前台的activity在一些时候会被其它的组件遮挡,导致这个activity暂停.举个样例.当一个半透明的activity被打开(比如一个dialog样式的activity), ...

  6. hdu1213 How Many Tables(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. BZOJ 3160 FFT+Manacher

    思路: 这道题思路好奇怪--. 我们先要知道关于x (x可以是间隙) 对称的有几对字母 显然暴力是n^2的 那怎么办呢 先把所有'a'看成1 'b'看成0 意外的发现 这不就是卷积嘛 再倒过来搞一搞 ...

  8. (转载)Android之有效防止按钮多次重复点击的方法(必看篇)

    为了防止测试妹子或者用户频繁点击某个按钮,导致程序在短时间内进行多次数据提交or数据处理,那到时候就比较坑了~ 那么如何有效避免这种情况的发生呢? 我的想法是,判断用户点击按钮间隔时间,如果间隔时间太 ...

  9. First-class citizen

    In programming language design, a first-class citizen (also type, object, entity, or value) in a giv ...

  10. c/s结构的自动化——pyautogui

    环境:Python 3.5.3 pip install pyautogui -i http://pypi.douban.com/simple --trusted-host pypi.douban.co ...