Php 我如何禁用;gii“;非管理员用户的代码生成器?
我正在为我的项目使用Yii 1.13框架,我需要“gii”代码生成器,但我只想将其限制为管理员用户,如何实现这一点?您可以通过IP限制用户,或者根据gii工具的属性选择密码Php 我如何禁用;gii“;非管理员用户的代码生成器?,php,yii,yii-components,Php,Yii,Yii Components,我正在为我的项目使用Yii 1.13框架,我需要“gii”代码生成器,但我只想将其限制为管理员用户,如何实现这一点?您可以通过IP限制用户,或者根据gii工具的属性选择密码 遵循以下步骤:- 从system.gii复制gii模块,即framework/gii 将其粘贴到项目的受保护的/modules文件夹中 在gii模块的GiiModule.php中进行以下更改 更改此设置 public function beforeControllerAction($controller, $action)
遵循以下步骤:-
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;
}
“模块”=>
排列(
'gii'=>数组(
'class'=>'application.modules.gii.GiiModule',
“密码”=>您的密码,
“ipFilters”=>数组('127.0.0.1','::1'),
),
),
注意:-我还没有测试过它。但它可能会给你一个如何继续的想法。这不是OP所要求的。即使未经验证的用户知道密码,他也可以使用Gii工具。@Touqeer Shafi我知道基于IP的过滤器,但如果普通用户知道密码,他可以轻松访问,我想阻止普通用户访问“Gii”,甚至登录page@GaneshGhalame普通用户如何知道gii工具的密码,由于此密码保存在您的配置文件中?@Touqeer Shafi,我的问题是禁用模块,即使普通用户知道或不知道密码,他也可以访问“gii”登录页面,为什么在未经授权的情况下,系统应在逻辑上向他们显示偶数登录页。@GaneshGhalame Gii工具仅为开发目的而创建,不建议您在生产服务器上使用它。因此,只需将其从配置文件中的模块阵列中删除即可。gii是一种开发工具,通常不应提供给经过身份验证的用户。查看如何实现.htaccess来限制生产服务器的所有访问,或者从实时部署中删除这些功能。
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;
}