【问题标题】:CakePHP: Weird Contain BehaviorCakePHP:奇怪的包含行为
【发布时间】:2012-02-27 21:42:29
【问题描述】:

我有一些非常奇怪的“包含”行为。每当我留下 $restaurants 注释时,$spas 都会返回包含的数据(在 beforeFilter() 中分配,但是当我取消注释 $restaurants 时,它会忽略包含语句。(我什至尝试克隆 $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);
} 

【问题讨论】:

  • 您是否尝试过将注释行更改为像$restaurants = $this->Coupon->find('all', array('conditions' => 'category_id' => 1, 'limit' => $showPerPage)) 这样的常规查找查询?

标签: cakephp


【解决方案1】:

您是否将此行为附加到 Coupon 模型的 $actsAs 变量中?

或者你可以附加在控制器上:

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

然后在任何你想要的地方分离:

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

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2017-06-15
    • 2012-08-08
    相关资源
    最近更新 更多