I have model A that implements BehaviorX (that extends CActiveRecordBehavior). Model B extends Model A, but I need to detach BehaviorX for that class.
$this->detach doesn’t work.
Code:
Model A
class Model_A extends CActiveRecord
{
public function behaviors(){
return array(
'BehaviorX' => array(
// parameters here
);
}
}
Model B
class Model_B extends Model_A
{
public functon init() { // this doesn't work
$this->detach('BehaviorX');
return parent::init();
}
public function behaviors(){ // this works but... sucks <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
$arr = parent::behaviors(); //retrieve behaviors array
unset($arr['BehaviorX']); // remove item with 'BehaviorX' index from behaviors array
return ($arr); //returns array without BehaviorX item.
}
}
Is there a better ‘Yii way’ to detach a behavior from a model? tia
danilo