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 ...
随机推荐
- Google翻译PDF文档
Google翻译PDF文档 翻译软件虽多如牛毛,但有关整段/全文翻译,堪用的软件极少, 涉及专业技术的文献.胜任翻译工作的人力稀缺.少不了project师讴心沥血. 由于多是PDF格式.即使要翻译个概 ...
- 实践补充 Installing Tomcat 7.0.x on OS X
我的 Mac 下是1.6的 SDK,下载 Tomcat 8.0 执行后,訪问 http://127.0.0.1:8080 并无反应,并且关闭脚本会报错 : Unsupported major.mino ...
- we标签
功能: · 辅助标签.配合其它标签使用,防止与标准html标签冲突 · 别名为test 使用方法: <we [name=key]>[value]</we& ...
- linux下通过命令启动多个终端运行对应的命令和程序
作者:张昌昌 在一些情况下,往往须要同一时候启动多个终端并让终端运行自己主动运行对应的命令,进而达到提高操作效率的目的.在linux下gnome-terminal启动终端命令, gnome-t ...
- Baby_Step,Gaint_Step(分析具体解释+模板)
下面是总结自他人博客资料.以及本人自己的学习经验. [Baby_Step,Gaint_Step定义] 高次同余方程. BL == N (mod P) 求解最小的L.因为数据范围非常大,暴力不行 这里用 ...
- JAVA配置Tomcat
1.下载tomcat,我jdk是1.8的,网上查了一下,说要安装tomcat8及以上的tomcat 尝试点击,弹出, 2.配置环境 3.安装通过cmd安装 4.点击开启服务 5.输入localhost ...
- iOS-MBProgressHUD使用
在码代码过程中,我们经常用到MBProgressHUD,但我很少实例化使用,一般都是偷个懒直接显示隐藏,这里贴上详解,以便日后有样式要求时使用. 1,MBProgressHUD常用属性和用法Demo ...
- 集群版本升级——rolling upgrade在ES 单节点从 restart 到加入集群,大概要 100s 左右的时间。也就是说,这 100s 内,该节点上的所有分片都是 unassigned 状态
集群版本升级 Elasticsearch 作为一个新兴项目,版本更新非常快.而且每次版本更新都或多或少带有一些重要的性能优化.稳定性提升等特性.可以说,ES 集群的版本升级,是目前 ES 运维必然要做 ...
- VM虚拟机上的CentOS 7系统重置root用户密码
1.开机在进入CentOS系统时(还未进入系统内)的系统选择页面时按E键进入系统编辑模式 2.找到Linux16开头的这行代码,用方向键将光标移动至这行代码的结尾,键入一个空格和rd.break,然后 ...
- 1.future线程通信
#include <future> #include<iostream> #include <thread> #include <thread> #in ...