thinkphp5项目--个人博客(六)
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项目--个人博客(六)的更多相关文章
- thinkphp5项目--个人博客(五)
thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(一)
thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(八)
thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(七)
thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(四)
thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(三)
thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(二)
thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- Do-Now—团队 冲刺博客六
Do-Now-团队 冲刺博客六 作者:仇夏 前言 终于从四级的考试中解脱了(不过我觉得可能凉凉,呵呵),我们的APP制作也迎来了最后的两天. 自己觉得自己其实没有干成什么事情,代码什么的大都是队友们写 ...
- 2015-2016-2 《Java程序设计》项目小组博客
2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...
随机推荐
- android启动第一个界面时即闪屏的核心代码(两种方式)
闪屏,就是SplashScreen,也能够说是启动画面,就是启动的时候,闪(展示)一下,持续数秒后.自己主动关闭. 第一种方式: android的实现很easy,使用Handler对象的postDe ...
- HDOJ 5294 Tricks Device 最短路(记录路径)+最小割
最短路记录路径,同一时候求出最短的路径上最少要有多少条边, 然后用在最短路上的边又一次构图后求最小割. Tricks Device Time Limit: 2000/1000 MS (Java/Oth ...
- 【IPC进程间通讯之三】内存映射文件Mapping File
IPC进程间通信+共享内存Mapping IPC(Inter-Process Communication.进程间通信). 文件映射(Mapping)是一种 ...
- UnrealEngine4初始化流程
自古以来全部的游戏引擎都分为三个大阶段:Init,Loop,Exit.UE4也不例外. 首先找到带有入口函数的文件:Runtime/Launch/Private/XXXX/LaunchXXXX.cpp ...
- dom 编程(html和xml)
html dom与xml dom关系: 什么是 DOM? DOM 是 W3C(万维网联盟)的标准. DOM 定义了訪问 HTML 和 XML 文档的标准: "W3C 文档对象模型 (DOM) ...
- pgsql数据库备份还原记
今天又搞了一个pgsql 的备份还原,差一点没有成功,以前总是想当然的用,没认真想背后的东西,也没对过程中的疑问做记录,所以后面也没什么印象,常见常新,这次既然又遇到就总结一下. 之前操作pgsql数 ...
- (三)Fegin声明式服务调用
上一篇,讲了SpringClound中的消费者采用Ribbon+Rest来实现,这回我们用组件Feign来实现服务的消费者,Fegin中也是默认集成了Ribbon的;和Eureka结合也能实现负载均衡 ...
- xshell同时发送多条命令
1.如图,勾选撰写栏 勾选全部会话 下面的是一个很方便的小技巧.分屏 如下图垂直排列 水平排列等等
- Spark 运行机制及原理分析
- 《汇编语言(第三版)》cmp指令
# cmp指令 本质 cmp是比较指令,cmp的功能相当于减法. 格式 cmp 操作对象1,操作对象2 功能 计算操作对象1-操作对象2,但并不保存结果,可以根据flag标志寄存器来判断结果. 正向判 ...