If you’ve used the console to create a basic web app, there will be a file called Controller.php in your protected/components folder. All of your controllers will extend from this class, so you can put global access controls in there if you like.
Thanks for reply. I had added this code in my but still that doesn’t work for me. Same above message is coming instead of error paga.
Please check below code.
Thanks
/**
Controller is the customized base controller class.
All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public function filters()
{
return array(
'accessControl',
);
}
public function accessRules()
{
return array(
array('allow',
'controllers'=>array('site'),
'actions'=>array('error'),
),
// More rules...
array('deny'),
);
}
Yes. Even I have each controller have there own access level. So mention both accessRules and filters functions in my all controllers.
<?php
class UserController extends Controller
{
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl',
);
}
public function accessRules()
{
}
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public function filters()
{
return array(
'accessControl',
);
}
public function accessRules()
{
return array(
array('allow',
'controllers'=>array('site'),
'actions'=>array('error'),
),
// More rules...
array('deny'),
);
}
}
There’s the problem; you’re overriding your rules each time, so the rules in Controller aren’t being used. I’m not sure of the best way to merge in the rules from the parent. The easiest option would be to just put all of your access rules in Controller rather than breaking them up. It’s all in one place then.