在Cells CakePhp 3中使用PaginatorHelper [英] Use PaginatorHelper in Cells CakePhp 3
问题描述
我正在尝试在一个单元格中使用Paginator,但Paginator的工作原理却很严格,但是该单元格模板中的PaginatorHelper却无法正常工作.
Hi I'm trying to use Paginator within a Cell the Paginator works rigth but the PaginatorHelper in the Template of the cell just doesn't work.
我正在使用CakePhp 3.5
I'm using CakePhp 3.5
这是我的代码
src/View/Cell/FinderCell.php
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
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>
我明白了
推荐答案
如果要使用帮助器,则需要使用分页参数填充请求对象,这是分页器组件通常为您执行的操作:
If you want to use the helper, then you need to populate either the request object with the pagination parameters, which is what the paginator component would normally do for you:
// ...
$this->request = $this->request->withParam(
'paging',
$paginator->getPagingParams() + (array)$this->request->getParam('paging')
);
$this->set(compact('pokemons'));
或分页器助手,后者依次在请求对象上设置参数:
or the paginator helper, which in turn sets the parameters on the request object:
// ...
$pagingParams = $paginator->getPagingParams();
$this->set(compact('pokemons', 'pagingParams'));
$this->Paginator->options(['paging' => $pagingParams]);
另请参见
- API> \ Cake \ Datasource \ PaginatorInterface :: getPagingParams()
- API> \ Cake \ View \ Helper \ PaginatorHelper :: options()
这篇关于在Cells CakePhp 3中使用PaginatorHelper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!