What to do if beforeAction return false?

My project uses Controller class as base class for all controllers.

I’ve overridden beforeAction method in it.

This method did nothing and therefore it returned not true.

I forgot about it.

After some time I came back to the project.

When I load the page the browser shows me empty screen.

I spent much time to find the cause.

In CController class I found that an action is not run

when beforeAction returns false but also no any error nor exception

are made. The system does just nothing!

CController class:

	$priorAction=$this->_action;


	$this->_action=$action;


	if($this->beforeAction($action))


	{


		$action->run();


		$this->afterAction($action);


	}


	$this->_action=$priorAction;

How to say the yii framework to treat beforeAction == false as error?

It’s not an error and can be used, for example, to prevent action from running.

I understand this. This behavior isn’t a bug. But why Yii doesn’t say anything about that.

My opinion it’s a drawback.

I think the system must throw exception by default.

When you lost a feedback with a system it’s always very bad.

Because then it’s difficult understand the source of a problem.

Why should Yii throw an exception if nothing’s wrong? If you want an exception, throw one from your beforeAction() method.

Hi, I’m trying to do what you sugested here.

In components/Controller.php i’ve added:




public function beforeAction($action) {


	if(Yii::app()->user->checkAccess($this->getId().'-'.$action->id))

		return true;


	throw new CHttpException(403,'You don\'t have permissions to access this page');

	// $this->redirect(array('site/error'));

}



And the problem is that I’m getting the exception printed on a white page, there is no layout, or css.

But when i throw the exception in any controller action everything works fine. (the error page is rendered ok


throw new CHttpException(403,'You don\'t have permissions to access this page');

In other words the actionError in the SiteController is not called if in Controller::beforeAction an exception is thrown, is there a work-around for this ?

I ended up rendering the whole site/error page.