我刚刚发现并开始使用基于角色的访问控制。
由于我使用的是 yii2 的高级模板,我想知道角色和权限是否在后端和前端层之间共享,或者它们是否是分开的。
例如
<?php
namespace appcommands;
use Yii;
use yiiconsoleController;
class RbacController extends Controller
{
public function actionInit()
{
$auth = Yii::$app->authManager;
// add "createPost" permission
$createPost = $auth->createPermission('createPost');
$createPost->description = 'Create a post';
$auth->add($createPost);
// add "author" role and give this role the "createPost" permission
$author = $auth->createRole('author');
$auth->add($author);
$auth->addChild($author, $createPost);
}
}
创作和创建帖子是否可用于后端和前端?
谢谢!
RBAC 组件基于公共部分..通常,如果它们基于数据库,则使用通用模型并共享相关的数据库表。
您可以在 main.php 的组件部分中声明此元素,在 cofig 区域中,如果您在共同的目录中执行此操作,则该组件 si 在环境(前端、后端(之间正确共享,并最终在您分发的所有应用程序之间共享 projectc。
例如:公共/配置/主.php
'components' => [
.....
'authManager' => [
'class' => 'yiirbacDbManager',
'cache' => 'cache',
....
],
这意味着它们可以在前端和后端之间自然共享。