Maybe something like:
public function onBeforeControllerInit($event)
{
$this->raiseEvent('onBeforeControllerInit', $event);
}
public function runController($route)
{
if(($ca=$this->createController($route))!==null)
{
list($controller,$actionID)=$ca;
$oldController=$this->_controller;
$this->_controller=$controller;
if($this->hasEventHandler('onBeforeControllerInit'))
$this->onBeforeControllerInit(new CEvent($controller));
$controller->init();
$controller->run($actionID);
$this->_controller=$oldController;
}
else
throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
array('{route}'=>$route===''?$this->defaultController:$route)));
}
Then from our components we could:
//component init() method maybe
Yii::app()->attachEventHandler('onBeforeControllerInit', array($this, 'runOnBeforeControllerInit'));
public function runOnBeforeControllerInit($event){
$c=$event->sender;
if(!($c instanceof SiteController))
return;
// do things like attach new behaviors, etc for the SiteController controller.
}
I'm asking this because most of the time i see myself searching for a way to hook from my components into controllers before they run, so that i can attach behaviors to them.

Help













