2012-02-27 83 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');