【问题标题】:Cakephp show number of items in pageCakephp 显示页面中的项目数
【发布时间】:2016-09-06 04:14:03
【问题描述】:

我正在使用 cakephp 框架。我一页有 10 个项目,第二页有 5 个项目。这些项目是从数据库中动态获取的。我想显示每页的项目数

例如:

第一页包含 10 个我想要输出的项目:1 个,共 10 个

第二页包含 5 个项目

我想要输出:15 个中的 11 个

谁能告诉我在这种情况下我会使用分页编码做什么。

我的代码如下

<?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->numbers(); ?>
<?php echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?> 

【问题讨论】:

    标签: php cakephp pagination


    【解决方案1】:

    你应该提到你正在使用的版本。

    CakePHP 3,请参考Creating a page counter in CakePHP 3.x

    echo $this->Paginator->counter('{{start}} of {{end}}');  // 1 of 10 (for page 1)
    

    CakePHP 2,请参考Creating a page counter in CakePHP 2.x

    echo $this->Paginator->counter('{:start} of {:end}');    
    

    【讨论】:

    • 非常感谢 Object Mnipulator :)
    【解决方案2】:

    您可以实现以下代码:

    将“格式”设置为范围会输出“1 - 5 of 15”:

    echo $this->Paginator->counter(array(
        'format' => 'range'
    ));
    

    更多信息请访问 cakebook 分页器助手 http://book.cakephp.org/3.0/en/views/helpers/paginator.html

    【讨论】:

      猜你喜欢
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多