Last active
December 17, 2015 10:29
-
-
Save cebe/5595588 to your computer and use it in GitHub Desktop.
Yii app controller events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller extends CController | |
{ | |
public function beforeAction($action) | |
{ | |
// register handler for the event | |
$this->attachEventHandler('onUserRegister', array(Yii::app()->myComponent, 'sendEMail')); | |
return parent::beforeAction($action); | |
} | |
// define event | |
public function onUserRegister($event) | |
{ | |
$this->raiseEvent('onUserRegister',$event); | |
} | |
} | |
class UserController extends Controller | |
{ | |
public function actionRegister() | |
{ | |
// register user here | |
// raise event afterwards | |
$this->onUserRegister(new CEvent()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment