Regarding the use of phpcms V9 clicks, there should be many direct calls to codes searched online. However, for some people who want to study and develop in depth, they are even more puzzled after seeing the codes on the Internet. I have been in the past few days. I took a look and learned something, so I’ll write it down and share it here. First, let’s understand the basics
pc_base::load_model(‘*<span style="color: #000000;">_model’) 加载数据库模型 pc_base::load_sys_class(‘classname’) 实例化系统类 pc_base::load_app_class(‘classname’,’admin’) 实例化模块类 pc_base::load_sys_func (‘funcfile’) 调用系统函数库</span>
<span style="color: #008080;">1</span> {pc:content action=<span style="color: #800000;">"</span><span style="color: #800000;">lists</span><span style="color: #800000;">"</span> catid=<span style="color: #800000;">"</span><span style="color: #800000;">$catid</span><span style="color: #800000;">"</span> num=<span style="color: #800000;">"</span><span style="color: #800000;">25</span><span style="color: #800000;">"</span> order=<span style="color: #800000;">"</span><span style="color: #800000;">id DESC</span><span style="color: #800000;">"</span> page=<span style="color: #800000;">"</span><span style="color: #800000;">$page</span><span style="color: #800000;">"</span> moreinfo=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;">} </span><span style="color: #008080;">2</span> <span style="color: #000000;">{loop $data $r} </span><span style="color: #008080;">3</span> {php $db = pc_base::load_model(<span style="color: #800000;">'</span><span style="color: #800000;">hits_model</span><span style="color: #800000;">'</span>); $_r = $db->get_one(array(<span style="color: #800000;">'</span><span style="color: #800000;">hitsid</span><span style="color: #800000;">'</span>=><span style="color: #800000;">'</span><span style="color: #800000;">c-</span><span style="color: #800000;">'</span>.$modelid.<span style="color: #800000;">'</span><span style="color: #800000;">-</span><span style="color: #800000;">'</span>.$r[id])); $views =<span style="color: #000000;"> $_r[views]; } </span><span style="color: #008080;">4</span> {php $comment_tag = pc_base::load_app_class(<span style="color: #800000;">"</span><span style="color: #800000;">comment_tag</span><span style="color: #800000;">"</span>, <span style="color: #800000;">"</span><span style="color: #800000;">comment</span><span style="color: #800000;">"</span>); $comment_total = $comment_tag->count(array(<span style="color: #800000;">'</span><span style="color: #800000;">commentid</span><span style="color: #800000;">'</span>=><span style="color: #800000;">'</span><span style="color: #800000;">content_</span><span style="color: #800000;">'</span>.$catid.<span style="color: #800000;">'</span><span style="color: #800000;">-</span><span style="color: #800000;">'</span>.$r[id].<span style="color: #800000;">'</span><span style="color: #800000;">-</span><span style="color: #800000;">'</span><span style="color: #000000;">.$modelid));} </span><span style="color: #008080;">5</span> <li><span <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">rt</span><span style="color: #800000;">"</span>>{date(<span style="color: #800000;">'</span><span style="color: #800000;">Y-m-d H:i:s</span><span style="color: #800000;">'</span>,$r[inputtime])}</span>·<a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[url]}</span><span style="color: #800000;">"</span> target=<span style="color: #800000;">"</span><span style="color: #800000;">_blank</span><span style="color: #800000;">"</span>{title_style($r[style])}>{$r[title]}</a> 点击:{$views} 评论数:{<span style="color: #0000ff;">if</span> $comment_total}{$comment_total}{<span style="color: #0000ff;">else</span>}<span style="color: #800080;">0</span>{/<span style="color: #0000ff;">if</span>}</li>{/<span style="color: #000000;">loop} </span><span style="color: #008080;">6</span> <span style="color: #000000;">{$pages} </span><span style="color: #008080;">7</span> {/pc}
The third line is the method of obtaining clicks. We will explain it separately:
$db = pc_base::load_model('hits_model')
The instantiated object is $db, and the instantiated class hit_model is loaded. The location of this class is in the root directory phpcmsmodelhit_model.class.php file
<span style="color: #0000ff;">class</span><span style="color: #000000;"> hits_model extends model { </span><span style="color: #0000ff;">public</span> $table_name = <span style="color: #800000;">''</span><span style="color: #000000;">; </span><span style="color: #0000ff;">public</span><span style="color: #000000;"> function __construct() { $</span><span style="color: #0000ff;">this</span>->db_config = pc_base::load_config(<span style="color: #800000;">'</span><span style="color: #800000;">database</span><span style="color: #800000;">'</span><span style="color: #000000;">); $</span><span style="color: #0000ff;">this</span>->db_setting = <span style="color: #800000;">'</span><span style="color: #800000;">default</span><span style="color: #800000;">'</span><span style="color: #000000;">; $</span><span style="color: #0000ff;">this</span>->table_name = <span style="color: #800000;">'</span><span style="color: #800000;">hits</span><span style="color: #800000;">'</span><span style="color: #000000;">; parent::__construct(); } }</span>
final <span style="color: #0000ff;">public</span> function get_one($<span style="color: #0000ff;">where</span> = <span style="color: #800000;">''</span>, $data = <span style="color: #800000;">'</span><span style="color: #800000;">*</span><span style="color: #800000;">'</span>, $order = <span style="color: #800000;">''</span>, $group = <span style="color: #800000;">''</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span> (is_array($<span style="color: #0000ff;">where</span>)) $<span style="color: #0000ff;">where</span> = $<span style="color: #0000ff;">this</span>->sqls($<span style="color: #0000ff;">where</span><span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> $<span style="color: #0000ff;">this</span>->db->get_one($data, $<span style="color: #0000ff;">this</span>->table_name, $<span style="color: #0000ff;">where</span><span style="color: #000000;">, $order, $group); }</span>
'-'.$r[id])) method is the data table The value of the field in v9_hits, the structure of its hits table is as follows
$_r at this time is a piece of data in the table. The field views in the data table is the number of clicks on this article, so use $_r[views] to get the number of clicks! ! ! Note: In the hitsid field data c-1-2, 1 represents the current model id and 2 represents the id of the current article