您的位置:首页 > 编程语言 > PHP开发

thinkphp实现文章访问量计数器

2016-08-08 16:40 155 查看
原理:每次刷新页面,执行一次某函数,某函数将数据表中的hit字段+1

不足:每次刷新,每次加1。

IndexController.class.php代码如下

public function showInfo(){
$id = $_GET['id']; //当点击文章标题,展开文章全文页面,传过去id
$info = M('Info');
$info->where(array('id' => $id))->setInc('hit',1);//hit字段+1

$arr=$info->find($id); //在showInfo.html输出
$this->assign('data',$arr);
$this->display();

}


showInfo.html代码如下

{$data.hit}


顺便附上index.html传id的代码

<a href="__URL__/showInfo/id/{$vo.id}" >{$vo.info_title}</a>


本文地址:http://liuyanzhao.com/3488.html

转载请注明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: