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. 洛谷 P3576 [POI2014]MRO-Ant colony

    P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...

  2. Oracle安装和使用说明

    很久没有安装Oracle了,今天试了一下重新安装Oracle,然后做了一个总结: 一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要 ...

  3. 每天学点Python之comprehensions

    每天学点Python之comprehensions 推导式能够简化对数据的处理,让代码简洁的同一时候还具有非常高的可读性.这在Python中非经常见. 列表推导式 通过列表推导式能够对列表中的全部元素 ...

  4. 葡萄城公布新版ActiveReports 9报表控件和报表server

    2014年11月10日---葡萄城宣布正式公布ActiveReports9,包含了三种报表模型:RDL报表.页面报表.区域报表.对于ActiveReports中的这个最新版本号中,我们专注于提高产品的 ...

  5. 设计模式入门之代理模式Proxy

    //代理模式定义:为其它对象提供一种代理以控制对这个对象的訪问 //实例:鉴于书中给出的样例不太好.并且有些疑问,所以直接用保护代理作为实例 //要求,一旦订单被创建,仅仅有订单的创建人才干够改动订单 ...

  6. duang!!!为什么函数能够返回unique_ptr

    C++虐我千百遍,我待C++如初恋 从智能指针说起 对高手而言.指针是上天入地的神器.对新手而言,那简直是灾难的源泉.高级语言如Java,C#都自己主动管理内存.你仅仅管new.不必担心内存释放问题. ...

  7. CxImage学习

    官方下载地址是:http://www.xdp.it/cximage/ 打开工程后可以看到下例这些工程: - CxImage - CxImageCrtDll - CxImageMfcDll - dome ...

  8. dll开发

    _declspec(dllexport) void fun() { }

  9. Edge浏览器的几个创意应用

    如果你跟我一样也喜欢书法,并且也有surface.那你可以进入我的网页.我给您准备了中国书法纸.信纸.方格子.对联等模板.满足您打发时间,精心抄佛经.诗歌,练书法等.开启Edge浏览器,开启涂鸦模式, ...

  10. 还是bib问题

    虽然昨天把添加bib的基本问题解决了,但是bib的参考文献没有了中括号.查了一下华东师大,只是给出了如何去掉中括号的方法. http://math.ecnu.edu.cn/~latex/doc.htm ...