Skip to content

Instantly share code, notes, and snippets.

@cebe
Last active December 17, 2015 10:29
Show Gist options
  • Save cebe/5595588 to your computer and use it in GitHub Desktop.
Save cebe/5595588 to your computer and use it in GitHub Desktop.
Yii app controller events
<?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