How To Pass Parameters To Event Handlers In Yii?

I have impressed the flexibility of Yii events. I am new to Yii and I want to know how to pass parameters to Yii event handlers?


//i have onLogin event defined in the login model

public function onLogin($event)

{

  $this->raiseEvent("onLogin", $event);

}

I have login handler defined in Handler class. this event handler method takes a parameter


function loginHandler($param1)

{

  ...

}

Here I am confuse HOW do I pass parameter to the login event handler?


//i attach login handler like this.

$loginModel->onLogin = array("handlers", "loginHandler");

$e = new CEvent($this);

$loginModel->onLogin($e);

Am I doing something wrong above? Is there another approach to do so? Thanks in advance.

Hi,

You can use Cvent param property.




$e = new CEvent($this, array('param1'=>'the value'));



You also have the sender property.

http://www.yiiframework.com/doc/api/1.1/CEvent