Cakephp发现OR条件不起作用

时间:2012-01-23 16:48:53

标签: mysql cakephp cakephp-2.0 cakephp-appmodel

我希望显示尚未过期的优惠券以及根本没有过期的优惠券。这是我的cakephp代码:

public function coupons() {

$this->paginate['Coupon']=array(
    'limit'=>9,
    'order'=>'RAND()',
    'OR'=>array(
            'expires' =>0,
            'Coupon.end_date >'=>date('Y-m-d')
            )
    );
$c=$this->paginate('Coupon');
$this->set('allcoupons', $c);

}

除了已过期的优惠券外,一切正常。他们仍然出现在我的结果中。我有一个测试记录在今天之前到期,但它仍然显示在我的结果中。我的'OR'条件是否写得不正确?

1 个答案:

答案 0 :(得分:4)

没关系。我想到了。你必须将'或'封装在'条件'之后,如下所示:

public function coupons() {

$this->paginate['Coupon']=array(
    'limit'=>9,
    'order'=>'RAND()',
    'conditions'=>array(
            'OR'=>array(
                'expires' =>0,
                'Coupon.end_date >'=>date('Y-m-d')
            ))
    );
$c=$this->paginate('Coupon');
$this->set('allcoupons', $c);

}
相关问题