CakePHP:奇怪的包含行为

时间:2012-02-27 21:42:29

标签: cakephp

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

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

1 个答案:

答案 0 :(得分:0)

您是否在优惠券模型的$actsAs变量中附加了此行为?

或者您可以在Controller上附加:

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

随时随地分开:

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