首页打开phpcms/modules/content/content.php,添加统计的控制器代码
在第18行下边加入
$this->db2 = pc_base::load_model('type_model');
即引入类型数据表,然后再添加代码:
第二部:增加content.tongji.tpl.php模板
- /*
- *统计测试
- */
- public function tongji() {
- $types = $this->db2->select();//获取分类
- if (is_array($types)){
- foreach ($types as $k => $type) {
- $modelid = $type['modelid'];
- if ($modelid == 0){
- $types[$k]['num'] = '0'; //为0时无法统计,给予0值
- }else{
- $this->db->set_model($modelid);
- $num = count($this->db->select());
- $types[$k]['num'] = $num;
- }
- }
- }
- include $this->admin_tpl('content_tongji');
- }
这个content.tongji.tpl.php的名字必须和
include $this->admin_tpl('content_tongji');
保持一致,根据phpcms的规则,后边加.tpl.php,所以在phpcms/modules/content/templates/下添加content.tongji.tpl.php模板
代码为:
第三步:添加后台访问路径
- <?php
- defined('IN_ADMIN') or exit('No permission resources.');$addbg=1;
- include $this->admin_tpl('header','admin');?>
- <div class="pad-10">
- <div class="table-list">
- <table width="100%" cellspacing="0" class="search-form">
- <tbody>
- <tr>
- <td>ID</td>
- <td>模型名称</td>
- <td>文章数量</td>
- </tr>
- <?php if (is_array($types)) {?>
- <?php foreach( $types as $r){ ?>
- <?php if ($r['modelid'] <>0){?> //去掉为0的情况
- <tr>
- <td><?php echo $r['modelid'];?></td>
- <td><?php echo $r['name'];?></td>
- <td><?php echo $r['num'];?></td>
- </tr>
- <?php }
- }
- }?>
- </tbody>
- </table>
- </div>
- </div>
根据第一步的函数名称,访问路径为http://您的域名/index.php?m=content&c=content&a=tongji,我把它放到了
phpcms/modules/content/templates/category_tree.tpl.php里边第58行
<br/>
<a href="?m=content&c=content&a=tongji" target='right'>文章统计</a>
然后这样就可以访问统计结果了!