2012-02-27 44 views
0

我有一些非常奇怪的'包含'行为。每当我离开$餐馆评论时,$ spas返回包含的数据(在beforeFilter()中分配),但是当我取消注释$ restaurants时,它忽略了包含语句(我甚至试图克隆$ spas函数并将其命名为“$餐馆”,同样的事情发生了..CakePHP:奇怪的包含行为

class CouponsController extends AppController { 

    public function beforeFilter() { 
     parent::beforeFilter(); 
     $this->Coupon->contain(array('Vendor' => array('VendorLocation'), 'Category')); 
    } 


    public function index() { 
     $showPerPage = 4; 


     //$restaurants = $this->Coupon->findAllBycategory_id('1', '', '', $showPerPage); 

     $spas = $this->Coupon->find('all', array('limit' => $showPerPage, 'conditions' => array('Coupon.category_id' => 3))); 
     $this->set('spas', $spas); 
} 
+0

您是否尝试将注释行更改为常规查找查询,如'$ restaurants = $ this-> Coupon-> find('all',array('conditions'=>'category_id'=> 1,'限制'=> $ showPerPage))'? – 2012-02-28 00:13:56

回答

0

你在$actsAs变量附上优惠券模式这种行为

或者你可以附上控制器:

$this->Coupon->Behaviors->attach('Containable'); 
$this->Coupon->contain(array('Vendor' => array('VendorLocation'), 'Category')); 

和分离你无论想要:

$this->Coupon->Behaviors->detach('Containable');