Question

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

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top