Difference between #1 and #2 of
Behaviors & events

Revision #2 has been created by phazei on Aug 6, 2010, 8:11:26 AM with the memo:

Added headers to sections
« previous (#1) next (#3) »

Changes

Title unchanged

Behaviors & events

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Content changed

These features provide endless possibilities and unbelievable flexibility, but as current documentation does not give more than a few examples, it might be difficult to fully understand their internals and requirements. It should be noted that they do mostly the same thing. You can attach behaviors and event handlers to components to modify the components' behavior. ##Events
 
 
It is useful when you want to interrupt the normal application flow without extending base classes.

For example, [enabling gzip](http://www.yiiframework.com/doc/cookbook/39/) compression on the output could be done via extending CWebApplication. But because there are entry points for event handlers, one can do this:
[...]
So, basically, it allows you build a list of function calls that can later be executed, in the order they were added. It can save you passing around a lot of object refs and building conditional code, since you can still raise the event, even if it doesn't do anything.

##Behaviors
 
 
Behaviors are simply a way of adding methods to an object. In an OO language like Ruby, it's quite possible to start with an 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.


```php
class SomeClass extends CBehavior
{
[...]
43 0
48 followers
Viewed: 160 370 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