【问题标题】:Use PaginatorHelper in Cells CakePhp 3在 Cells CakePhp 3 中使用 PaginatorHelper
【发布时间】:2017-11-10 00:04:53
【问题描述】:

您好,我正在尝试在单元格中使用 Paginator,Paginator 工作正常,但单元格模板中的 PaginatorHelper 不起作用。

我正在使用 CakePhp 3.5

这是我的代码

src/View/Cell/FinderCell.php

namespace App\View\Cell;
use Cake\View\Cell;
use Cake\Datasource\Paginator;
class FinderCell extends Cell {

    public function display() {
        $this->loadModel('Pokemon');
        $paginador = new Paginator();

        $pokemons = $paginador->paginate(
            $this->Pokemon->find()
        );

        $this->set(compact('pokemons'));
    }
}

src/Template/Cell/Finder/display.ctp

<?php 
foreach ($pokemons as $pokemon) :
 ?>
<div class="tipo form large-2 medium-2 columns content">
    <?php echo $this->Html->image($pokemon->pokemon_image) ?>
</div>
<?php endforeach; ?>

<div class="paginator">
    <ul class="pagination">
        <?= $this->Paginator->prev('<< Anterior') ?>
        <?= $this->Paginator->numbers() ?>
        <?= $this->Paginator->next('Siguiente >>') ?>
    </ul>
    <p><?= $this->Paginator->counter() ?></p>
</div>

我明白了

【问题讨论】:

    标签: cakephp pagination cakephp-3.0


    【解决方案1】:

    如果你想使用帮助器,那么你需要用分页参数填充请求对象,这是分页器组件通常会为你做的:

    // ...
    
    $this->request = $this->request->withParam(
        'paging',
        $paginator->getPagingParams() + (array)$this->request->getParam('paging')
    );
    
    $this->set(compact('pokemons'));
    

    或分页器助手,它反过来设置请求对象的参数:

    // ...
    
    $pagingParams = $paginator->getPagingParams();
    
    $this->set(compact('pokemons', 'pagingParams'));
    
    $this->Paginator->options(['paging' => $pagingParams]);
    

    另见

    【讨论】:

      猜你喜欢
      • 2011-08-14
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多