Event Handling

Hi All,

I have been working since 5 months in Yii framework. I am quite confused how to do coding for event handling from controller, let me tell you how much i have understood about Event handling in Yii.

[size="2"]1. Events are like to be generated in between any action for example, if a user get registered after registration he must be notified by an email. method actionRegister() in the controller.[/size]

  1. The event are written inside a component (e.g. Data) and the event methods are prefixed by "on" like onAfterRegiter()

  2. CONFUSION : What does the code below means

class Data extends CComponent 


	public function onAfterRegister($event)


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



in the above code the "[size="2"]public function onAfterRegister($event)[/size][size="2"]" is itself an event handler and we are invoking it with the statement [/size]

[size=“2”]$this->raiseEvent(‘onAfterRegister’, $event); inside it![/size]

[size="2"]4. CONFUSION : In the actionRegister() from the controller we are writing like this [/size]

public function actionRegister()


	$e = new CEvent($this); // creating an object of event

	$data = new Data; // initiate component

[size="2"] [/size]

	// what does it means 

	$data->onClicked = function ($event) {

		echo "Hi";


	// firing the event 

	$data->onClicked($e);  // out put is "Hi"

[size="2"]i followed [/size]This wiki post

[size="2"]Any one help me with the correct procedure and understand how its working…[/size]