Paginate无视条件

时间:2014-07-03 15:34:09

标签: cakephp cakephp-2.5

当我尝试运行此代码时,它不会更改我的查询,只是没有采取条件:

$this->paginate = array(
    'conditions' => array(
        'campaign_id' => $this->request->data['Campaign']['campaign_id']
    )
);

$this->set('products', $this->Paginator->paginate());

查询看起来像这样

SELECT
    `Product`.`id`, `Product`.`campaign_id`, `Campaign`.`id`, `Campaign`.`title`, `Campaign`.`text`
FROM
    `db`.`products` AS `Product`
    LEFT JOIN
        `db`.`campaigns` AS `Campaign` ON (`Product`.`campaign_id` = `Campaign`.`id`)
WHERE
    1 = 1
LIMIT
    20

我的语法有什么问题吗?

(CakePHP 2.5.1)

1 个答案:

答案 0 :(得分:1)

@ndm的意思是将现有代码替换为:

$this->Paginator->settings['conditions'] = array(
    'Product.campaign_id' => $this->request->data['Campaign']['campaign_id']
)
$this->set('products', $this->Paginator->paginate());