0

Here's the code I'm using to get the records. I need to know is there any thing like find first 100 or top 100 records and then paginate it. the db will contain 1000's of records ;)

$options = array(
        'limit' => 10,
        'recursive' => 0
        );
$this->paginate = $options;
$this->set('movies',$this->paginate());

Everything working fine, But I need just top 100 records and pagination only for that 100 records. I searched in many places, I couldn't find. Hope someone will help me :)

4

2 回答 2

3

尝试组合limitorder选项一起获得结果。

array(
    'order' => array('created' => 'desc')
    'limit' => 100,
)

这里“创建”是时间戳表列。如果说“top”,您的意思是最新记录,那么您应该使用“desc”,否则使用“asc”。

更新

我之前的示例是针对find功能的,而不是针对分页的。似乎您正在寻找如何将分页用于记录子集。目前没有内置选项。你应该看看其他答案,看看解决方案是否适合你。

于 2012-08-22T04:04:01.200 回答
0

为前 100 名创建自定义查找方法,您可以将其与分页一起使用:

示例: http ://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-custom-find

于 2012-08-23T14:51:02.660 回答