2012-01-23 40 views
0

我正在寻找显示尚未过期的优惠券以及根本没有到期的优惠券。这里是我的CakePHP代码:Cakephp发现OR条件不起作用

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'条件写错了吗?

回答

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); 

}