我正在为我的项目使用Yii 1.13框架,我需要" gii"代码生成器,但我想仅限管理员用户,我该如何实现?
答案 0 :(得分:2)
按照以下步骤操作: -
更改此
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
$route=$controller->id.'/'.$action->id;
if(!$this->allowIp(Yii::app()->request->userHostAddress) && $route!=='default/error')
throw new CHttpException(403,"You are not allowed to access this page.");
$publicPages=array(
'default/login',
'default/error',
);
if(Yii::app()->user->isGuest && !in_array($route,$publicPages))
Yii::app()->user->loginRequired();
// check your admin conditions here
elseif(!isset(Yii::app()->user->isAdmin) || !Yii::app()->user->isAdmin)
throw new CHttpException(403,"You are not allowed to access this page.");
else
return true;
}
return false;
}
在 config / main.php
中 'modules' =>
array(
'gii'=>array(
'class'=>'application.modules.gii.GiiModule',
'password'=> Your password,
'ipFilters'=>array('127.0.0.1','::1'),
),
),
注意: - 我还没有测试过它。但它可能会让你知道如何继续。