简体   繁体   English

yii2-RBAC-它在后端和前端之间共享吗?

[英]yii2 - RBAC - is it shared between backend and frontend?

I have just discovered and started using Role Based Access control . 我刚刚发现并开始使用基于角色的访问控制

Since I am using an advanced template for yii2, I am wondering if roles and permissions are shared between backend and frontend tiers or if they are separated. 由于我正在为yii2使用高级模板,因此我想知道后端和前端层之间是否共享角色和权限,或者它们是否分开。

For example 例如

<?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);

    }
}

would author and createpost be available for both backend and frontend? 后端和前端都可以使用author和createpost吗?

thank you! 谢谢!

The RBAC componet are base on common part .. typically if they are base on DB you use common models and shared the related db table .. RBAC组件基于公共部分。通常,如果它们基于数据库,则使用公共模型并共享相关的数据库表。

You can declare this element in component section of main.php in cofig area and if you do this in common dir this component si correctly shared between both the enviroment (frontend , backend) and eventually between all apps you distribute you projectc.. 您可以在cofig区域的main.php的组件部分中声明此元素,如果在公共目录中执行此操作,则此组件可以在环境(前端,后端)之间以及最终在您分发给projectc的所有应用之间正确共享。

eg : common/config/main.php 例如:common / config / main.php

      'components' => [
    .....
    'authManager' => [
        'class' => 'yii\rbac\DbManager',
        'cache' => 'cache',
          ....
    ],

this mean they could be naturally shared between frontend and backend .. 这意味着它们可以在前端和后端之间自然共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM