【问题标题】:CakePHP 3.x - How to pass pagination configuration directly instead of using the controller `$paginate` property?CakePHP 3.x - 如何直接传递分页配置而不是使用控制器的`$paginate` 属性?
【发布时间】:2016-08-12 20:21:45
【问题描述】:

以下代码有效:

// Somewhere in the Controller
public $paginate = [ 'maxLimit'=>2 ];
// In the method:
$query=$this->Model->find('all')->where(....);
$this->set('results',$this->paginate($query));

但是,我不想在控制器中将 $paginate 指定为 public。我宁愿根本不指定它。我试图将 maxLimit 设置移动到该方法,但我做错了。如何更改以下代码?

$query=$this->Model->find('all')->where(....);
$this->set('results',$this->paginate($query, ['maxLimit'=>2]));

【问题讨论】:

    标签: cakephp configuration pagination cakephp-3.x


    【解决方案1】:

    Controller::paginate() 方法不接受第二个参数。您正在寻找的是 Paginator 组件的 paginate() 方法,它可以通过 $this->Paginator 属性在您的控制器中访问。

    $this->Paginator->paginate($query, ['maxLimit' => 2])
    

    另见

    【讨论】:

    • 你知道我问题的所有答案 :) 谢谢你分享你的知识。
    猜你喜欢
    • 1970-01-01
    • 2015-11-09
    • 2013-08-29
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2016-12-29
    • 2020-09-17
    相关资源
    最近更新 更多