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. ASP.NET-权限管理五张表

    ASP.NET 权限管理五张表 权限管理的表(5张表) 每个表里面必有的一些信息 序号 名称  字段  类型   主键 默认值 是否为空 备注 1  用户ID  ID      INT     是   ...

  2. HDU 2879

    利用x<n的信息,可以证得当n为素数时,he[n]=2;同时,若n 为素数,则有HE[N^K]=2;因为若等式成立则有n|x(x-1).抓住这个证即可. 至于符合积性函数,想了很久也没想出来,看 ...

  3. [Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests

    In a proper unit test we want to isolate external dependencies as much as possible to guarantee a re ...

  4. 多线程003 - 再谈CyclicBarrier

      java.util.concurrent.CyclicBarrier也是JDK 1.5提供的一个同步辅助类(为什么用也呢?參见再谈CountDownLatch).它同意一组线程互相等待,直到到达某 ...

  5. oracle 11g sql developer安装后无法使用

    oracle11g安装后出现   再去官网单独下来个sql developer安装 sql developer须要jre支持

  6. shadowOffset 具体解释

    x向右为正,y向下为正 1.y<0 UILabel *label=[[UILabelalloc] initWithFrame:CGRectMake(40,40, 250,50)]; label. ...

  7. php利用href进行页面传值的正确姿势

    首先在a.php中 <?php $a = "world"; echo "<a href='b.php?m=$a'>删除</a>"; ...

  8. hpuoj--1122-- HH的随机数(数据去重)

    1122: HH的随机数 时间限制: 1 Sec  内存限制: 128 MB 提交: 476  解决: 75 [提交][状态][讨论版] 题目描述 HH想在学校中请一些同学一起做一项问卷调查,为了实验 ...

  9. 正则表达式匹配 C++实现 java实现 leetcode系列(十一)

    给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符 '*' 匹配零个或多个前面的那一个元素 所谓匹配,是要涵盖 整个 字符串  ...

  10. Swift学习笔记(8):闭包

    目录: 基本语法 尾随闭包 值捕获 自动闭包 闭包是自包含的函数代码块,闭包采取如下三种形式之一: ・全局函数是一个有名字但不会捕获任何值的闭包 ・嵌套函数是一个有名字并可以捕获其封闭函数域内值的闭包 ...