【问题标题】:Manage pagination with cell in cakephp 4在 cakephp 4 中使用单元格管理分页
【发布时间】:2022-02-16 20:18:45
【问题描述】:

使用 Cakephp 4 我想显示一些数据。由于数据太多,我只想使用分页,我不想重新加载整个页面,只是显示这些数据的部分。所以我创建了一个这样的单元格: 文件Cell.php

public function display() {
  $results = $paginator->paginate(
            $query,
            $this->request->getQueryParams(),
            [
                'limit' => 20
            ]
        );
  }
  $paging = $paginator->getPagingParams() + (array)$this->request->getParam('paging');
  $this->request = $this->request->withParam('paging', $paging);

  $this->set('res', $results);

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

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

除了这样做我重新加载整个页面而我只想重新加载与单元格有关的部分之外,有人可以帮助我吗?

【问题讨论】:

  • 使用 ajax 和一些 js 插件来加载和分页网站的那部分。
  • 谢谢,我试试看。

标签: cakephp pagination cell


【解决方案1】:

我只是 Cake 的初学者,但我想知道你的 Controller 中的 finder 函数是否可以接受页面参数?

我没有例子,但我很快就会做类似的事情。

【讨论】:

    【解决方案2】:

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

    <div id="test">
    </div>
    

    而且,在我的 ajax 响应中,我添加:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多