【问题标题】:Cakephp paginator jump with multiple pagesCakephp分页器跳转多个页面
【发布时间】:2016-11-16 20:35:25
【问题描述】:

我使用 cakephp 3.x 分页器,我收到了客户的请求。

例子:

  • 我的分页栏,现在它位于#1。

<< | < | **1** 2 3 4 5 6 7 8 9 | > | >>

  • 当我点击“>>”时,栏将显示 10-19 并位于 #10

<< | < | **10** 11 12 13 14 15 16 17 18 19 | > | >>

  • 再次点击“>>”,会显示20-29,站在#20

<< | < | **20** 21 22 23 24 25 26 27 28 29 | > | >>

  • 与“

“>”和“

所以我的问题是:

  • 如何使用 cakephp 分页助手制作“>>”和“

我在 view.ctp 中的代码是

<?php 
  echo $this->Paginator->first(<<);

  echo $this->Paginator->prev('<');

  echo $this->Paginator->numbers();

  echo $this->Paginator->next('>');

  echo $this->Paginator->last(>>);
?>

【问题讨论】:

  • &lt;&lt;&gt;&gt;使用单/双引号...first('&lt;&lt;'),last('&gt;&gt;')
  • 对不起,我没明白你的意思。
  • 把这个echo $this-&gt;Paginator-&gt;first(&lt;&lt;);替换成这个echo $this-&gt;Paginator-&gt;first('&lt;&lt;');,和last一样
  • 对不起,它不适合我的要求。当我点击>>时,它会移动到页面的末尾。
  • 因为first()last()同时代表第一页和最后一页

标签: php cakephp pagination cakephp-3.0 paginator


【解决方案1】:

不幸的是,没有内置的分页器辅助方法可以创建这样的链接,您可能想file a feature request,我认为这是一个不错的补充。

话虽如此,您可以手动构建此类跳转链接,分页器助手提供所需的一切,即当前页码、检查给定页面是否存在的方法以及从助手生成链接的功能模板。

这是一个基本示例,如果该页面存在,这将为当前页面 + 10 生成一个跳转链接:

$page = $this->Paginator->current() + 10;
if ($this->Paginator->hasPage($page)) {
    echo $this->Paginator->templater()->format('nextActive', [
        'url' => $this->Paginator->generateUrl(['page' => $page]),
        'text' => '>>',
    ]);
}

另见

Templater docs are currently missing 出于某种原因...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多