Browse Source

Added back the events for Controller.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
7a587f62a6
  1. 16
      framework/yii/base/Controller.php

16
framework/yii/base/Controller.php

@ -18,6 +18,15 @@ use Yii;
class Controller extends Component class Controller extends Component
{ {
/** /**
* @event ActionEvent an event raised right before executing a controller action.
* You may set [[ActionEvent::isValid]] to be false to cancel the action execution.
*/
const EVENT_BEFORE_ACTION = 'beforeAction';
/**
* @event ActionEvent an event raised right after executing a controller action.
*/
const EVENT_AFTER_ACTION = 'afterAction';
/**
* @var string the ID of this controller * @var string the ID of this controller
*/ */
public $id; public $id;
@ -192,7 +201,9 @@ class Controller extends Component
*/ */
public function beforeAction($action) public function beforeAction($action)
{ {
return true; $event = new ActionEvent($action);
$this->trigger(self::EVENT_BEFORE_ACTION, $event);
return $event->isValid;
} }
/** /**
@ -203,6 +214,9 @@ class Controller extends Component
*/ */
public function afterAction($action, &$result) public function afterAction($action, &$result)
{ {
$event = new ActionEvent($action);
$event->result = & $result;
$this->trigger(self::EVENT_AFTER_ACTION, $event);
} }
/** /**

Loading…
Cancel
Save