php - How to pass parameters to event handlers in yii? -


i impressed flexibility of yii events. new yii , want know how pass parameters yii event handlers?

//i have onlogin event defined in login model public function onlogin($event) {   $this->raiseevent("onlogin", $event); } 

i have login handler defined in handler class. event handler method takes parameter:

function loginhandler($param1) {   ... } 

but here, confused how pass parameter login event handler:

//i attach login handler this. $loginmodel->onlogin = array("handlers", "loginhandler"); $e = new cevent($this); $loginmodel->onlogin($e); 

am doing wrong? there approach this?

now have answer own question. cevent class has public property called params can add additional data while passing event handler.

//while creating new instance of event $params = array("name" => "my name");  $e = new cevent($this, $params); $loginmodel->onlogin($e);   //adding second parameter allow me add data can accessed in  // event handler function. loginhandler in case. function loginhandler($event)// have event parameter.  {    echo $event->params['name']; //will print : "my name"  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -