Answer the question
In order to leave comments, you need to log in
In Yii 1.x, hang a hook to check the access rights to the controller action?
Is it possible in Yii 1.x to hang your hook specifically for checking access rights to the controller action?
For example, we have a certain controller:
class MyController extends Controller
{
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
public function accessRules()
{
return array(
array('allow',
'roles'=>array('root', 'admin', 'manager'),
),
array('allow',
'actions'=>array('send', 'list'),
'users'=>array('*'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
Answer the question
In order to leave comments, you need to log in
You can define override the beforeControllerAction method, it is called before the filters are executed
/**
* The pre-filter for controller actions.
* This method is invoked before the currently requested controller action and all its filters
* are executed. You may override this method in the following way:
* <pre>
* if(parent::beforeControllerAction($controller,$action))
* {
* // your code
* return true;
* }
* else
* return false;
* </pre>
* @param CController $controller the controller
* @param CAction $action the action
* @return boolean whether the action should be executed.
*/
public function beforeControllerAction($controller,$action)
{
if(($parent=$this->getParentModule())===null)
$parent=Yii::app();
return $parent->beforeControllerAction($controller,$action);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question