component events and behaviours?

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?

and this code:

public function onClicked($event)


$this->raiseEvent('onClicked', $event);


what is happening, where do i put this code? what does it do?

would be helpful!

Cookbook helps again:

CComponent is just a base class for most of Yii classes. It provides magic methods __get, __set and other.

but i still dont understand what a component is? is it model,or/and controller?

if not: when do i create one and what is it for? where do i put it in and from where do i call it in plain english?

and what is an event? im sorry, read through the cookbooks tutorials but didnt get any smarter:/

i mean, in jquery an event (mouse click) is coupled to a html element and these are both coupled to a event handler. so when user clicks on the element, it triggers the event handler.

the event and function event is in javascript code.

$.(’#element’).click(function() { code });

the element is in html code.

<button id=‘element’ />

i need this kind of information so i know what is going on from step 1 to that the handler is triggered.


Pretty much every … uhm … component of Yii is a component. ;) I’m lacking a better word here. CComponent simply defines some base methods/properties that every component in Yii should share. Like the guide says, every component is made for a specific task and thus can be configured or customized without affecting other components of the application.

Another word for event would be “interesting moment”. You can attach handlers if you want something to happen at one of those moments. Like “OnBeginRequest”, meaning: The application starts now to process the request. If you need something to happen at that moment, attach a handler to that event. That way you can couple components even though they don’t know about each other.

It’s the same concept as for browser events.