cakephp与计数问题分页

时间:2012-01-16 17:48:58

标签: cakephp pagination cakephp-1.3 cakephp-2.0 paginate

我在controller操作中编写了以下代码。

$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中获取错误结果。

这是什么问题?我不知道。请帮助。

2 个答案:

答案 0 :(得分:1)

得到了答案。访问此链接。

http://wiltonsoftware.com/posts/view/custom-group-by-pagination-and-a-calculated-field

感谢您的帮助。

答案 1 :(得分:0)

你是控制器定义helpers变量吗?如果不是,则默认包含Paginator帮助程序。如果确实如此,你必须记得自己加入它。

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