【问题标题】:Error when using Paginator in Cakephp在 Cakephp 中使用 Paginator 时出错
【发布时间】:2018-07-10 18:03:33
【问题描述】:

我有一个用于分页数据的变量 $paginator

在我的控制器中

public $paginator = [
    'limit'=>5,
    'order'=>[
        'author'=>'desc'
    ]
];

在我的视图模板(.ctp)中

<?= $this->Paginator->prev('<< pre') ?>
<?= $this->Paginator->next('next >>')?>
<?= $this->Paginator->counter() ?>

但我收到很多错误:

注意(8):未定义索引:pageCount [CORE/src/View/Helper/PaginatorHelper.php,第 591 行] 注意(8):未定义索引:count [CORE/src/View/Helper/PaginatorHelper.php, line 595] 注意(8):未定义索引:perPage [CORE/src/View/Helper/PaginatorHelper.php,第 598 行] 注意(8):未定义索引:count [CORE/src/View/Helper/PaginatorHelper.php, line 599] 注意(8):未定义索引:count [CORE/src/View/Helper/PaginatorHelper.php, line 600] 注意(8):未定义索引:页面[CORE/src/View/Helper/PaginatorHelper.php,第613行] 注意(8):未定义索引:当前 [CORE/src/View/Helper/PaginatorHelper.php,第 615 行] 注意(8):未定义索引:count [CORE/src/View/Helper/PaginatorHelper.php, line 616]

我知道只有这一行会导致错误

<?= $this->Paginator->counter() ?>

我无法分页。 为什么会这样? :(

【问题讨论】:

  • 显示该视图的整个控制器操作
  • 哦。谢谢你。谢谢你,我在控制器中看到了我的失踪。我还没有声明分页 $paginate = $this->paginate($this->Articles); $this->set(compact('$paginate'));
  • 我想是的 :)

标签: cakephp-3.0 paginator


【解决方案1】:

在控制器分页属性中

public $paginate = [
        'States' => ['scope' => 'states'],
        'Lgas' => ['scope' => 'lgas'],
];

在控制器动作中

  $lgas = $this->paginate($this->Lgas, ['scope' => 'lgas']);
  $states = $this->paginate($this->States, ['scope' => 'states']);
  $this->set(compact('lgas', 'states'));

在视图中

<div class="paginator">
        <ul class="pagination">
            <?=$this->Paginator->first('<< ' . __('first'), ['model' => 'Lgas', 'tab' => 'lga'])?>
            <?=$this->Paginator->prev('< ' . __('previous'), ['model' => 'Lgas', 'tab' => 'lga'])?>
            <?=$this->Paginator->numbers(['model' => 'Lgas', 'tab' => 'lga'])?>
            <?=$this->Paginator->next(__('next') . ' >', ['model' => 'Lgas', 'tab' => 'lga'])?>
            <?=$this->Paginator->last(__('last') . ' >>', ['model' => 'Lgas', 'tab' => 'lga'])?>
        </ul>
        <p><?=$this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total'), 'model' => 'Lgas', 'tab' => 'lga'])?></p>
    </div>

    <div class="paginator">
        <ul class="pagination">
            <?=$this->Paginator->first('<< ' . __('first'), ['model' => 'States'])?>
            <?=$this->Paginator->prev('< ' . __('previous'), ['model' => 'States'])?>
            <?=$this->Paginator->numbers(['model' => 'States'])?>
            <?=$this->Paginator->next(__('next') . ' >', ['model' => 'States'])?>
            <?=$this->Paginator->last(__('last') . ' >>', ['model' => 'States'])?>
        </ul>
        <p><?=$this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total'), 'model' => 'States'])?></p>
    </div>

【讨论】:

    猜你喜欢
    • 2016-02-17
    • 2022-08-02
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    相关资源
    最近更新 更多