84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
yii2 rbac 每次走一个方法都要自己验证一次用户有没有该控制器与Action的权限吗?如果是配置的话怎么配置?
闭关修行中......
yii\filters\AccessRule::matchCalllback. 注意传递的参数 $rule, $action
[ 'actions' => ['special-callback'], 'allow' => true, 'matchCallback' => function ($rule, $action) { # write arbitrary access check logic # permission = (rule [xxoo] action) # return user->can(permission); } ]
或者使用下面的方式, 见 yii2-admin
return [ 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\PhpManager', // or use 'yii\rbac\DbManager' ] ], 'as access' => [ 'class' => 'mdm\admin\components\AccessControl', ], ];
AccessControl 支持配置 role
例如:
[ 'actions' => ['edit'], 'allow' => true, 'roles' => ['@', 'author'], ],
yii\filters\AccessRule::matchCalllback. 注意传递的参数 $rule, $action
或者使用下面的方式, 见 yii2-admin
AccessControl 支持配置 role
例如: