我试图在我的Yii2高级应用程序中使用RBAC(sweetlix / yii2-redis-rbac和yiisoft / yii2-redis已安装)。
//....
'components' => [
'authManager' => [
'class' => 'sweelix\rbac\redis\Manager',
'db' => 'redis',
],
// ...
],
//....
'components' => [
'authManager' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 1,
],
// ...
],
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
}
第364行的sweelix \ rbac \ redisManager:如果$ item-> ruleName为null,我们有错误...
$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
我在其他应用程序和环境中检查过它,并注意到它适用于版本"yiisoft/yii2-redis": "2.0.8"
和"yiisoft/yii2-redis": "2.0.9"
它会产生错误(第364行的sweelix \ rbac \ redisManager:$ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);
)。如果强行切换到软件包的“2.0.8”版本,则错误消失。