gpt4 book ai didi

cakephp - 如何限制cakephp中的分页

转载 作者:行者123 更新时间:2023-12-04 03:34:18 29 4
gpt4 key购买 nike

如何限制cakephp中的分页?

假设我有400条记录。
我只需要从第50条记录到第75条记录中获得25条记录
并且每页需要显示5条记录。
我该如何做到分页?

样例代码:

        $this->paginate = array(
'contain'=>array('User'),
'recursive' => 2,
'order' => array('Profile.winning' => 'DESC'),
'limit' =>5

);

最佳答案

您可以设置分页条件。

function listRecords()
{
$this->paginate = array(
'conditions' => array('Model.id >=' => 50, 'Model.id <=' => 75),
'limit' => 5
);
$this->paginate('Model');
);

编辑:

来自 here的解决方案:
$this->paginate = array(
'limit' => 20,
'totallimit' => 1000
);

然后在模型中:
public function paginateCount($conditions = null, $recursive = 0, $extra = array())
{
if( isset($extra['totallimit']) ) return $extra['totallimit'];
}

关于cakephp - 如何限制cakephp中的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152416/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com