yii2 - RBAC - 它在后端和前端之间共享吗?
yii2 - RBAC - is it shared between backend and frontend?
我刚刚发现并开始使用 Role Based Access control。
由于我使用的是 yii2 的高级模板,我想知道角色和权限是在后端和前端层之间共享还是分开。
例如
<?php
namespace app\commands;
use Yii;
use yii\console\Controller;
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);
}
}
author 和 createpost 是否可用于后端和前端?
谢谢!
RBAC 组件基于公共部分.. 通常,如果它们基于数据库,您可以使用公共模型并共享相关数据库 table ..
您可以在 cofig 区域 main.php 的组件部分中声明此元素,如果您在公共目录中执行此操作,则此组件将在环境(前端、后端)之间以及最终在您的所有应用程序之间正确共享分发你的项目c..
例如:common/config/main.php
'components' => [
.....
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache' => 'cache',
....
],
这意味着它们可以在前端和后端之间自然共享..
我刚刚发现并开始使用 Role Based Access control。
由于我使用的是 yii2 的高级模板,我想知道角色和权限是在后端和前端层之间共享还是分开。
例如
<?php
namespace app\commands;
use Yii;
use yii\console\Controller;
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);
}
}
author 和 createpost 是否可用于后端和前端?
谢谢!
RBAC 组件基于公共部分.. 通常,如果它们基于数据库,您可以使用公共模型并共享相关数据库 table ..
您可以在 cofig 区域 main.php 的组件部分中声明此元素,如果您在公共目录中执行此操作,则此组件将在环境(前端、后端)之间以及最终在您的所有应用程序之间正确共享分发你的项目c..
例如:common/config/main.php
'components' => [
.....
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache' => 'cache',
....
],
这意味着它们可以在前端和后端之间自然共享..