点击量是指阅读次数吗知乎(phpcms v9文章点击数是哪个表哪个字段)
导读:phpcms v9文章点击数是哪个表哪个字段...
phpcms v9文章点击数是哪个表哪个字段
phpcms v9文章点击数在hits表的views字段 。
详解:
获取点击数的实例
{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"} {loop $data $r} {php $db = pc_base::load_model(hits_model); $_r = $db->get_one(array(hitsid=>c-.$modelid.-.$r[id])); $views = $_r658 次浏览; } {php $comment_tag = pc_base::load_app_class("comment_tag", "comment"); $comment_total = $comment_tag->count(array(commentid=>content_.$catid.-.$r[id].-.$modelid));} <li><span class="rt">{date(Y-m-d H:i:s,$r[inputtime])}</span>·<a href="{$r[url]}" target="_blank"{title_style($r[style])}>{$r[title]}</a> 点击:{$views} 评论数:{if $comment_total}{$comment_total}{else}0{/if}</li>{/loop} {$pages} {/pc}其中的第3行是获取点击数:
$db = pc_base::load_model(hits_model)实例化对象为 $db ,加载实例化类hit_model ,该类的位置在 根目录\phpcms\model\hit_model.class.php文件中
class hits_model extends model { public $table_name = ; public function __construct() { $this->db_config = pc_base::load_config(database); $this->db_setting = default; $this->table_name = hits; parent::__construct(); } }该类文件加载继承了model类文件并且继承了其内部的方法 ,所以下面调用get_one()方法
$_r = $db->get_one(array(hitsid=>c-.$modelid.-.$r[id])) 调用$db对象中的get_one方法该方法位于hits_model继承的model类中代码如下
final public function get_one($where = , $data = *, $order = , $group = ) { if (is_array($where)) $where = $this->sqls($where); return $this->db->get_one($data, $this->table_name, $where, $order, $group); }get_one(arr(hitsid=>c-.$modelid.-.$r[id]))方法中传递的数组为数据表v9_hits中的字段的值 ,其 hits 表的结构如下
此时的$_r为该表中的一条数据 数据表中的字段 views 即为该篇文章的点击次数 所以使用 $_r658 次浏览即可获取点击数啦!
注:hitsid 字段的数据 c-1-2 中 1表示当前模型id 2表示当前文章的id
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!