2012-01-16 48 views
0

我已经在我的controller操作中编写了以下代码。cakephp与计数问题的分页

$this->paginate['Tag'] = array(
      'fields' => array('COUNT(tag_id) AS numbers', 'tag', 'slug'), 
      'limit' => 50, 
      'order' => 'numbers desc', 
      'recursive' => 2, 
      'group' => array('tag'), 
     ); 
$tags = $this->paginate('Tag', array('not' => array('site_id' => NULL), 'tag !=' => '')); 

并写在.ctp文件的代码如下。

<div class="row section"> 
    <div class="col col_16 pagination"> 
     <h3>Tags</h3> 
     <?php 
     foreach ($tags as $key => $tag) { 
      echo '<span>' . $this->Html->link($tag['Tag']['tag'] . ' (' . $tag[0]['numbers'] . ')', '/tags/' . $tag['Tag']['slug']) . '</span>'; 
     } 
     ?> 
    </div> 
    <div class="col col_16 pagination"> 
     <?php 
     echo $this->Paginator->first('First', null, null, array('class' => 'disabled')); 
     echo $this->Paginator->prev('Previous', null, null, array('class' => 'disabled')); 
     echo $this->Paginator->numbers(array('separator' => '')); 
     echo $this->Paginator->next('Next', null, null, array('class' => 'disabled')); 
     echo $this->Paginator->last('Last', null, null, array('class' => 'disabled')); 
     ?> 
    </div> 
    <div class="col col_16 pagination"> 
     <h5 class="margin0Px"> 
      <?php 
      echo $this->Paginator->counter(array(
       'format' => __('Page %page% of %pages%, showing %current% out of %count% total, starting on %start%, ending on %end%.', true) 
      )); 
      ?> 
     </h5> 
    </div> 
</div> 

获得虚假结果的看法$this->Paginator

这里有什么问题?我没有任何想法。请帮助。

+0

更好地发布.ctp将发布标记变量的结果,如果有的话 - CTP真的没有关系。 (顺便说一句,你是否设置了变量?:$ this-> set('tags',$ tags); – Dave 2012-01-16 17:54:04

+0

@Dave是的,我已经设置它 – gautamlakum 2012-01-16 17:56:23

回答

0

您控制器是否定义了helpers变量?如果它没有默认包含Paginator助手。如果是这样,你必须记住要自己包含它。

文档:http://book.cakephp.org/1.3/en/view/1096/Using-Helpers

+0

没有必要将它添加到帮助程序中如果我删除COUNT tag_id)从字段和'组'的数字=>数组('标签'),它工作正常。 – gautamlakum 2012-01-16 18:15:28