简体   繁体   中英

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.

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?

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 ..

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..

eg : common/config/main.php

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

this mean they could be naturally shared between frontend and backend ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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