phpcms V9 secondary development------(detailed explanation of getting clicks)
Oct 22, 2016 am 12:00 AMRegarding 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’) 加載數(shù)據(jù)庫(kù)模型 pc_base::load_sys_class(‘classname’) 實(shí)例化系統(tǒng)類 pc_base::load_app_class(‘classname’,’admin’) 實(shí)例化模塊類 pc_base::load_sys_func (‘funcfile’) 調(diào)用系統(tǒng)函數(shù)庫(kù)</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> 點(diǎn)擊:{$views} 評(píng)論數(shù):{<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>The array passed in the get_one(arr('hitsid'=>
'-'.$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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)