Yii Framework Forum: Additional Behavior Methods - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Additional Behavior Methods Rate Topic: -----

#1 User is offline   dajwindler 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-December 09
  • Location:South Korea

Posted 22 April 2010 - 09:31 AM

I have a question about Behaviors.

If I create a custom behavior B with methods B.beforeSave(), B.afterFind(), and B.someFunction(), is there a way that my model M could specifically make a call to B.someFunction()?

Is it possible to get the Behavior objects from within my model and make the call directly?
0

#2 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,648
  • Joined: 17-January 09
  • Location:Russia

Posted 22 April 2010 - 11:49 AM

Yes. This is commonly used when two or more behaviors with the same name and different parameters are assigned to a model.

class Product extends CActiveRecord {

  function behaviors(){
    return array(
      'internalColor' => array(
        'class' => 'ext.yiiext.behaviors.model.taggable.ETaggableBehaviour',
      ),
      'externalColor' => array(
        'class' => 'ext.yiiext.behaviors.model.taggable.ETaggableBehaviour',
      ),
    );
  }

}


$product->internalColor->myBehaviorMethod();
$product->externalColor->myBehaviorMethod();

Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   dajwindler 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-December 09
  • Location:South Korea

Posted 22 April 2010 - 05:22 PM

Thank you for your help.

Your answers solves my question completely.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users