CakePHP 3.x - 如何直接传递分页配置而不是使用控制器 `$paginate` 属性?

CakePHP 3.x - How to pass pagination configuration directly instead of using the controller `$paginate` property?

以下代码有效:

// 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]));

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

在您的控制器中访问该方法
$this->Paginator->paginate($query, ['maxLimit' => 2])

另见