0
中可容纳的行为不为我预计的CakePHP 2.1.2以下代码:中可容纳“包含”属性不重
class ReportCard extends AppModel {
....
// debug shows expected results
public function test1(){
$this->Behaviors->attach('Containable');
$params = array(
'conditions' => array('ReportCard.id' => 1),
'contain' => array(
'ReportCardGradingPeriodCollection' => array(
'GradingPeriodCollection')));
debug($this->find('first', $params));
$this->Behaviors->detach('Containable');
}
// Unexpected: debug shows same array as test1
public function test2(){
$this->Behaviors->attach('Containable');
$params = array(
'conditions' => array('ReportCard.id' => 1),
'contain' => array(
'ReportCardGradingPeriodCollection' => array(
'GradingPeriodCollection' => array(
'GradingPeriodCollectionDetail' => array(
'GradingPeriod')))));
debug($this->find('first', $params));
$this->Behaviors->detach('Containable');
}
}
调用来自控制器的功能,当我得到意想不到的效果。 test1()
显示预期的数组。 test2()
示出了从test1
同一阵列。如果我运行test2()
然后test1()
我得到预期的结果(大阵,然后小阵)。
class ReportCardsController extends AppController {
....
public function test(){
$this->ReportCard->test1();
$this->ReportCard->test2();
}
}
我在模型而不是动态加载每个函数的行为使用actAs
尝试过,但没有帮助。
我道歉,如果我失去了一些东西简单。提前致谢!
我放置'公共$ actsAs =阵列( '中可容纳');''中AppModel'。这没有帮助。 – Rob