Home > php教程 > php手册 > body text

phpcms V9 secondary development------(detailed explanation of getting clicks)

WBOY
Release: 2016-10-22 00:00:07
Original
1375 people have browsed it

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>
Copy after login
The above are the four methods of calling models and instantiating objects
pc_base::load_model(‘*_model’) corresponds to loading the class files under the root directory phpcmsmodel
pc_base::load_sys_class(‘classname’) corresponds to loading the files under the root directory phpcmslibsclasses
pc_base::load_app_class(‘classname’,’admin’) corresponds to loading the files under the root directory phpcmsmodulesadminclasses
pc_base::load_sys_func (‘funcfile’) corresponds to loading the root directory phpcmslibsfunctions
The following is an example of obtaining clicks
<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}
Copy after login

The third line is the method of obtaining clicks. We will explain it separately:

$db = pc_base::load_model('hits_model')  
Copy after login

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>
Copy after login
This class file load inherits the model class file and inherits its internal methods, so the get_one() method is called below
$_r = $db->get_one(array('hitsid'=> [id])) Call the get_one method in the $db object. This method is located in the model class inherited by hits_model. The code is as follows
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>
Copy after login
The array passed in the get_one(arr('hitsid'=>
'c-'
.
$modelid
.

'-'.$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

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!