【问题标题】:yii2 - RBAC - is it shared between backend and frontend?yii2 - RBAC - 它在后端和前端之间共享吗?
【发布时间】:2016-02-12 10:52:33
【问题描述】:

我刚刚发现并开始使用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 吗?

谢谢!

【问题讨论】:

  • Yii2 中最好的 Rbac 教程 www.freetuts.org/tutorial/view?id=6

标签: php yii yii2 yii2-advanced-app rbac


【解决方案1】:

RBAC 组件基于公共部分.. 通常如果它们基于 DB,则您使用公共模型并共享相关的 db 表..

您可以在 cofig 区域的 main.php 的组件部分中声明此元素,如果您在公共目录中执行此操作,则此组件将在环境(前端、后端)之间以及最终在您分发给您的所有应用程序之间正确共享 projectc。 .

例如:common/config/main.php

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

这意味着它们可以自然地在前端和后端之间共享..

【讨论】:

  • 如何添加权限,如果它与两个模块共享?表示如何添加模块以及控制器/动作等。
  • @AhmadAsjad 发布了一个适当的具体问题 ..(或者如果你已经完成了链接,请给我评论)用适当的样本进行了很好的描述
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
  • 2016-07-31
  • 1970-01-01
  • 2021-10-28
  • 2017-09-11
  • 2020-03-13
  • 1970-01-01
相关资源
最近更新 更多