YII2如何在accesscontrol中允许调试/默认/工具栏
我在web.php文件中有以下配置,强制用户在使用应用程序之前先登录YII2如何在accesscontrol中允许调试/默认/工具栏,yii2,yii2-basic-app,Yii2,Yii2 Basic App,我在web.php文件中有以下配置,强制用户在使用应用程序之前先登录 'as access' => [ 'class' => \yii\filters\AccessControl::className(), //AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'],
'as access' => [
'class' => \yii\filters\AccessControl::className(), //AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'], // add all actions to take guest to login page
'allow' => true,
'roles' => ['@'],
],
],
],
但是我在http://localhost/yii2/debug/default/toolbar?tag=58759099581f2
如何在规则中允许这样做?首先,此配置不正确。本部分:
[
'actions' => ['logout', 'index'], // add all actions to take guest to login page
'allow' => true,
'roles' => ['@'],
],
另外,将只允许对经过身份验证的用户执行注销
和索引
操作。需要将其更改为:
[
'allow' => true,
'roles' => ['@'],
],
允许访问整个站点。然后,您可以在AccessControl
或特定控制器的操作中进一步自定义访问权限。因此,在您的案例中,调试并不是唯一被禁止的页面
我想它是从相关问题复制粘贴到这里的
顺便说一下,调试已经在基本应用程序的应用程序配置中启用:
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
// Below Gii is enabled too, code is omitted for brevity
}
所以,当用户通过身份验证时,您将可以毫无问题地访问调试模块
注意:通过此配置登录
和错误
每个控制器的操作都允许未经身份验证的用户执行。小心点。其他控制器中可能存在具有类似名称的操作
更新:实际上,您可以更进一步,通过以下方式使此解决方案更加灵活:
- 将完全允许的控制器放置在
列表中(如果在模块内,则在其前面加上模块名称),以完全允许它们(允许所有操作)$allowedControllers
- 将允许的操作放在
列表中(如果它属于模块,则用控制器名称和模块名称作为前缀)$allowedActions
登录
和错误
)上完全访问本地服务器上的调试模块,这非常有用
这还可以防止来自不同模块/控制器的操作名称重合。您必须启用工具栏action web.php配置文件:
'rules' => [
[
'actions' => ['login', 'error', 'toolbar'],
'allow' => true,
],
'rules' => [
[
'actions' => ['login', 'error', 'toolbar'],
'allow' => true,
],