Difference between #4 and #5 of
Behaviors & events

Revision #5 has been created by Lensi on Mar 30, 2011, 7:37:57 AM with the memo:

language
« previous (#4) next (#6) »

Changes

Title unchanged

Behaviors & events

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Content changed

[...]
```
Now $classInstance has all the methods from MySuperClass1 and MySuperClass2. Since MySuperClass2 is being used as a behavior, it has to extend CBehavior.
The only caveat to this is an attached behavior cannot override any class methods of the component it is being attached to. If a method already exists, if it be from the original class or already added by a previously attached behavior, it will not be overwritten.


In an OO language like Ruby, it's quite possible to start with a
n completely empty object and simply build its behavior as you go along. Yii provides this behavior with a little magic. The key is that the class you wish to add the behavior from must extend Cbehavior.
[...]
So, in this case, you are extending the functionality of an object with functionality of another object.

After studying this cookbook page
it isyou are encouraged to reread the [corresponding guide page](http://www.yiiframework.com/doc/guide/basics.component) as it contains advanced information (for example, if you are familiar with interfaces, you might find it enough to implement IBehavior before extending CBehavior).
43 0
48 followers
Viewed: 160 373 times
Version: 1.1
Category: Tutorials
Tags:
Written by: pestaa
Last updated by: Gismo
Created on: Aug 24, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history