使用cakephp 4中的单元格管理分页

klr1opcd  于 2022-11-11  发布在  PHP
关注(0)|答案(2)|浏览(166)

在Cakephp 4中,我想显示一些数据。由于数据太多,我只想使用分页,我不想重新加载整个页面,只想重新加载显示这些数据的部分。因此,我创建了一个单元格,如下所示:fileCell.php

  1. public function display() {
  2. $results = $paginator->paginate(
  3. $query,
  4. $this->request->getQueryParams(),
  5. [
  6. 'limit' => 20
  7. ]
  8. );
  9. }
  10. $paging = $paginator->getPagingParams() + (array)$this->request->getParam('paging');
  11. $this->request = $this->request->withParam('paging', $paging);
  12. $this->set('res', $results);

并在视图中显示分页,如下所示:

  1. <div class="instances index content">
  2. <div class="paginator">
  3. <ul class="pagination">
  4. <?= $this->Paginator->first('<< ' . __('first')) ?>
  5. <?= $this->Paginator->prev('< ' . __('previous')) ?>
  6. <?= $this->Paginator->numbers() ?>
  7. <?= $this->Paginator->next(__('next') . ' >') ?>
  8. <?= $this->Paginator->last(__('last') . ' >>') ?>
  9. </ul>
  10. <p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
  11. </div>
  12. </div>

除了这样做,我重新加载整个页面,而我想重新加载有关细胞的部分,有人能帮助我吗?

lztngnrs

lztngnrs1#

我只是Cake的初学者,但我想知道控制器中的finder函数是否可以接受页面参数?
我没有例子,但我很快就会做类似的事情。

wh6knrhe

wh6knrhe2#

我 做 了 一 个 标准 的 ajax 调用 , 在 我 的 控制 器 中 创建 函数 , 创建 与 我 的 元素 相 对应 的 视图 , 在 我 的 主 视图 中 ( 我 将 放置 我 的 元素 ) , 添加 div :

  1. <div id="test">
  2. </div>

中 的 每 一 个
而且 , 在 我 的 ajax 响应 中 , 我 补充 道 :

  1. $('#test').html(response);

格式
之后 , 我 通常 使用 cakephp 分页 来 管理 元素 的 分页 。

相关问题