I have a model which has a certain behaviour implemented.

class X 
{
....
    public function behaviours() 
    {
    return array (
        'YBehaviour' => array (
            'class' => 'application.path.to.class.y',
    );
    }
....
}

The thing is that, for the moment, I'm detaching it more than needing it. How can I 'reverse' this? What I mean is, instead of detaching it every time i don't need it, I want to attach it everytime I do need it.

Thanks

有帮助吗?

解决方案

From this Yii wiki page (http://www.yiiframework.com/wiki/44/behaviors-events/)

class MyBoringClass extends MySuperClass1 {
}

$classInstance = new MyBoringClass();
$classInstance->attachbehavior('uniqueName', new MySuperClass2);

I believe that is what you are after

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top