yii2 rbac 检查角色 user->can()

bda*_*art 5 database rbac yii2

我使用 DBManager 在 yii2 中安装并配置了 rbac,但我没有得到“检查”:

if (Yii::$app->user->can('waitAccess')) {
    echo "yes it is pending.";
} else {
    echo "nothing";
}
Run Code Online (Sandbox Code Playgroud)

我创建了 3 个具有不同角色的用户,但每个人都可以看到第一行,尽管他们没有权限。“在我看来”

这是我的 rbacController

<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;

class RbacController extends Controller
{
public function actionInit()
{
    $auth = Yii::$app->authManager;

    // add "user2View" permission
    $user2View = $auth->createPermission('user2View');
    $user2View->description = 'user2 view';
    $auth->add($user2View);

    // add "user1View" permission
    $user1View = $auth->createPermission('user1View');
    $user1View->description = 'user1 view';
    $auth->add($user1View);

    // add "waitAccess" permission
    $waitAccess = $auth->createPermission('waitAccess');
    $waitAccess->description = 'wait for Access';
    $auth->add($waitAccess);

    // add "seeConfig" permission
    $seeConfig = $auth->createPermission('seeConfig');
    $seeConfig->description = 'Access to the administrative Config';
    $auth->add($seeConfig);

    // add "user2" role and give this role the "user2View" permission
    $user2 = $auth->createRole('user2');
    $auth->add($user2);
    $auth->addChild($user2, $user2View);

    // add "user1" role and give this role the "user1View" permission
    $user1 = $auth->createRole('user1');
    $auth->add($user1);
    $auth->addChild($user1, $user1View);

    // add "pending" role and give this role the "waitAccess" permission
    $pending = $auth->createRole('pending');
    $auth->add($pending);
    $auth->addChild($pending, $waitAccess);

    // add "superadmin" role and give this role the "seeConfig" permission
    $superadmin = $auth->createRole('superadmin');
    $auth->add($superadmin);
    $auth->addChild($superadmin, $seeConfig);
    $auth->addChild($superadmin, $user2View);
    $auth->addChild($superadmin, $user1View);
    $auth->addChild($superadmin, $waitAccess);

}
}
Run Code Online (Sandbox Code Playgroud)

也许有人知道我可以寻找什么。

更新:这是我的数据库结构 我的 yii2 rbac 的数据库结构

更新2:

我解决了!愚蠢的人没有查看记录所有用户的默认规则。所以每个人都可以访问。删除该行并添加待定标准即可解决问题。