tags:

views:

473

answers:

1

i'm currently learning the yii framework and have read their documentation.

but i still don't understand the components. what are these. they talk about component events and behaviors.

could someone explain these terms for me and give me real app examples of what a component, its events and behaviors could be?

would be helpful!

+2  A: 

A CComponent by itself doesn't do much. It's very much like a QObject in Qt. A CComponent can raise events, and can have delegates to events (through attachEventHandler()).

Regarding behaviours, the manual says:

The methods of the behavior can be invoked as if they belong to the component. Multiple behaviors can be attached to the same component.

To attach a behavior to a component, call attachBehavior; and to detach the behavior from the component, call detachBehavior.

A behavior can be temporarily enabled or disabled by calling enableBehavior or disableBehavior, respectively. When disabled, the behavior methods cannot be invoked via the component.

Starting from version 1.1.0, a behavior's properties (either its public member variables or its properties defined via getters and/or setters) can be accessed through the component it is attached to.

Which gives you the possibility to simulate a signals and slots mechanism, or the strategy pattern (by enabling or disabling behaviours).

Most of the classes in Yii have CComponent as a base class.

As a user, you'll see the benefits they provide through the mechanisms mentioned above when you'll create your own components (under protected/components/).

You can find a good starting point for implementing components here: http://www.yiiframework.com/doc/guide/basics.component

Flavius