Hi,
I need to attach some behaviors dynamically because they have the same methods but different implementation. To reduce the overhead of attaching the same behavior multiple times I need to check if a behavior had already been attached. I have tried to get the current behavior using ‘asa’ method, but it always returns null even when I call Video::model()->findAll().
My code is like this:
class Video extends CActiveRecord
{
public function afterFind()
{
parent::afterFind();
$behavior = $this->videoSite . 'Behavior';
$curBehavior = $this->asa('siteBehavior');
var_dump($curBehavior); // this always returns null
if (is_null($curBehavior) || !($curBehavior instanceof $behavior))
$this->attachBehavior('siteBehavior', $behavior);
}
}
Is there something that I miss here?