CakePHP 3.x-如何直接通过分页配置而不是使用控制器的`$ paginate`属性? [英] CakePHP 3.x - How to pass pagination configuration directly instead of using the controller `$paginate` property?

查看:52
本文介绍了CakePHP 3.x-如何直接通过分页配置而不是使用控制器的`$ paginate`属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有效:

// 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设置移至该方法,但操作不正确.如何更改以下代码?

However, I do not want to specify $paginate as public in the controller. I would rather not specify it at all. I tried to move maxLimit setting to the method but I'm doing it incorrectly. How can I change the below code?

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

推荐答案

The Controller::paginate() method doesn't take a second argument. What you are looking for is the paginate() method of the Paginator component, which is accessible in your controller via the $this->Paginator property.

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

另请参见

这篇关于CakePHP 3.x-如何直接通过分页配置而不是使用控制器的`$ paginate`属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆