【问题标题】:How to create template for cakephp paginator?如何为 cakephp 分页器创建模板?
【发布时间】:2020-05-17 04:17:46
【问题描述】:

我正在尝试在 cakephp 分页器助手中应用 bootstrap 4 分页样式。

对我来说看起来很难。

这是我想在分页器助手中应用的简单 html

<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item"><a class="page-link" href="#">Previous</a></li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item"><a class="page-link" href="#">Next</a></li>
  </ul>
</nav>

我在配置位置创建了一个分页器模板文件。

config/paginator-templates.php

return [
    'number' => '<a href="{{url}}">{{text}}</a>',
];

然后我已经在appView.php中初始化了

public function initialize(): void
{
       $this->loadHelper('Paginator', ['templates' => 'paginator-templates']);
}

之后出现错误

Config file "paginator-templates.php" did not return an array

如何在 cakephp 中创建 paginator-templates.php 以应用 bootstrap 4 分页设计?有没有博客或例子?

【问题讨论】:

    标签: cakephp pagination cakephp-4.x


    【解决方案1】:

    返回的文件是什么?

    解决此问题的一种方法可能是在帮助程序上使用setTemplate() 方法。

    https://book.cakephp.org/3/en/views/helpers/paginator.html#changing-templates-at-run-time

    使用您提供的示例代码,我已经能够让代码在 Cake 3.8.5 中运行

    我想知道您是否忘记了模板文件中的开头 &lt;?php 标记,所以它以字符串形式返回。

    【讨论】:

      猜你喜欢
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2017-04-22
      相关资源
      最近更新 更多