Pao*_*ino 13
根据文档,该find()
方法的第二个参数是一个$params
数组.
传递此数组的可能值之一是limit
关键.所以你可以做到以下几点:
$users = $this->User->find('all', array('limit' => 200));
Run Code Online (Sandbox Code Playgroud)
"我喜欢它的数组('limit'=> 21,'page'=> 1),用于在一个页面中分页21个用户.如果我将限制更改为200,那么它只在一个页面中为200个用户分页...在这种情况下如何限制与适当的分页?? - 匿名2009年5月14日在7:22"
是的,你可以像有人提到的那样使用cakePHP分页助手.但是在某些情况下,您可能希望自己进行分页或仅限制每次调用检索的记录数.这里有什么值得我处理这种情况的方法.
比如说你想要每页检索一定数量的记录,然后:$ start = 0; - >这是为了从第一个开始检索记录.如果你需要说,例如,从31日开始,那么$ start = 30;
所以,$ start = 0; $ length = 20; //我们将从第一条记录开始检索20条记录
代码将是这样的:
// To retrieve a number of Products per page
$products = $this->Product->find('all', array(
'order' => 'product_number ASC',
'limit' => $start.','.$length,
'recursive' => -1
)
);
Run Code Online (Sandbox Code Playgroud)