我正在尝试在我的 Yii2 高级应用程序中使用RBAC (已安装sweelix/yii2-redis-rbac和yiisoft/yii2-redis)。
常见/main.php:
//.... 'components' => [ 'authManager' => [ 'class' => 'sweelix\rbac\redis\Manager', 'db' => 'redis', ], // ... ],
常见/主要本地.php:
//.... 'components' => [ 'authManager' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'localhost', 'port' => 6379, 'database' => 1, ], // ... ],
让我们尝试初始化(RbacController):
public function actionInit() { $auth->removeAll(); $user = $auth->createRole('user'); $auth->add($user); $admin = $auth->createRole('admin'); $auth->add($admin); $auth->addChild($admin, $user); $auth->assign($admin, 1); // 1 - is id of admin user on database }
php yii rbac/init
返回:
Error: Redis error: ERR wrong number of arguments for 'hget' command. Redis command was: HGET auth:mappings:rules
对象转储:
$user = $auth->createRole('user');
var_dump($user);die;
返回:
object(yii\rbac\Role)#21 (7) {
["type"]=> int(1)
["name"]=> string(4) "user"
["description"]=> NULL
["ruleName"]=> NULL
["data"]=> NULL
["createdAt"]=> NULL
["updatedAt"]=> NULL
}
sweelix\rbac\redisManager在第364行:如果 $item->ruleName 为空,我们有错误...
$ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);
版本:
Redis server v=3.2.6
,
"yiisoft/yii2": "~2.0.14"
,
yiisoft/yii2-redis 2.0.8
,
PHP 7.0.33