我一直在使用yii2高级模板,现在我想实现
一些RBAC进入我的前端项目的控制器。
我对Yeesoft的/Yii2 cms RBAC控制面板印象深刻
https://github.com/yeesoft/yii2-yee-cms
虽然我可能不会使用他们的很多内容管理功能。然而,我对它的控制面板印象深刻,我想用它来控制前端访问,给我的员工一定的权限。
我已将此代码包含在其前端\配置\ main中。php的组件部分。
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager'
],
]
这使我能够在前端控制器中包含如下代码
if (!\Yii::$app->user->can('createEmployee')) {
throw new \yii\web\ForbiddenHttpException('You do not have permission to create an employee.');
}
控制访问。
我正在使用yeesoft的数据库,并正在考虑将我的所有数据从前端数据库迁移到yeesoft的cms数据库,因为我可以使用控制面板在其下创建权限并访问权限数据,而无需使用
Yii::$app->authManager;
以及其他类似以下的复杂代码:
$auth = Yii::$app->authManager;
//create the permission
$manageCleansbutnotusers = $auth->createPermission('manageCleansbutnotusers');
$manageCleansbutnotusers->description = 'Manage Cleans but not Users';
//add the permission
$auth->add($manageCleansbutnotusers);
//create the permission
$manageCleansandusers = $auth->createPermission('manageCleansandusers');
$manageCleansandusers->description = 'Manage Cleans and Users';
//add the permission
$auth->add($manageCleansandusers);
//create the role
$moderator = $auth->createRole('moderator');
$moderator->description = 'Moderator';
//add the role
$auth->add($moderator);
//attach the permissions to the role
$auth->addChild($moderator, $manageCleansbutnotusers);
//create the role
$admin = $auth->createRole('admin');
$admin->description = 'Administrator';
//add the role
$auth->add($admin);
//attach both permissions to the admin role
$auth->addChild($admin, $moderator);
$auth->addChild($admin, $manageCleansandusers);
我过去曾将其用于迁移目的。
有人能告诉我什么是更好的方法吗?我确信有人使用Yeesoft cms控制面板来控制对前端的访问,而无需采取以下措施:
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager'
],
]