cakephp:做2次查询之后的Paginate

时间:2014-03-01 08:16:48

标签: php cakephp pagination paginator

如何在进行2次查询后​​进行分页?

我有:

   $this->Paginator->settings = array(
                'conditions' => array('Record.status =' => 'published',  
                                              'RecordUser.flagged =' => null, 
                              'Record.category_id =' => $likes
                                ),
                'limit' => 5,
                'order' => array('rate' => 'desc')
            );

我也希望这样做:

$this->Paginator->settings = array(
                'conditions' => array('Record.status =' => 'published',  
                                              'RecordUser.flagged =' => null, 
                              'Record.category_id !=' => $likes
                                ),
                'limit' => 5,
                'order' => array('rate' => 'desc')
            );

然后合并结果.. 问题是第一个查询限制为5的结果然后继续到第二页。我希望第二个查询结果显示之前第一个查询的所有结果。

我该怎么做? 我正在使用cakephp 2.4.3

1 个答案:

答案 0 :(得分:0)

为什么你不能只做一个查询并使用订单?

$likes = implode(',', $likes);

$this->YourModel->virtualFields['in_like'] = "IF(Record.category_id IN ($likes), 0, 1)";

$this->Paginator->settings = array(
    'conditions' => array(
        'Record.status =' => 'published',  
        'RecordUser.flagged =' => null, 
     ),
     'limit' => 10,
     'order' => array('in_like' => 'asc', 'rate' => 'desc')
);