【问题标题】:cakephp pagination with count issuecakephp分页计数问题
【发布时间】:2012-02-11 15:17:56
【问题描述】:

我在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-&gt;Paginator 中得到错误结果。

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

【问题讨论】:

  • 发布 .ctp 会更好地发布 tags 变量的结果,如果有的话 - CTP 真的无关紧要。 (顺便说一句,你设置变量了吗?:$this->set('tags', $tags);

标签: cakephp cakephp-1.3 cakephp-2.0 pagination


【解决方案1】:

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

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

【讨论】:

  • helpers 中不需要添加。如果我从字段和 'group' => array('tag') 中删除 COUNT(tag_id) AS 编号,它可以正常工作。
猜你喜欢
  • 2016-12-25
  • 2013-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多