簡體   English   中英

yii2-RBAC-它在后端和前端之間共享嗎?

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

我剛剛發現並開始使用基於角色的訪問控制

由於我正在為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組件基於公共部分。通常,如果它們基於數據庫,則使用公共模型並共享相關的數據庫表。

您可以在cofig區域的main.php的組件部分中聲明此元素,如果在公共目錄中執行此操作,則此組件可以在環境(前端,后端)之間以及最終在您分發給projectc的所有應用之間正確共享。

例如:common / config / main.php

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

這意味着它們可以在前端和后端之間自然共享。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM