windhoney / yii2-rest-rbac

yii2 rbac yii2 rest RBAC Auth manager for Yii2 RESTful(YII2权限管理rbac--rest接口方式)
https://windhoney.gitbooks.io/yii2-rest-rbac/
MIT License
82 stars 20 forks source link

mauth_item表中没有‘parent_name’字段,但是代码中使用了 #11

Closed wayne798 closed 6 years ago

wayne798 commented 7 years ago

RouteController中

 public function getRoutes()
    {
        $manager = Yii::$app->getAuthManager();
        $routes = $this->getAppRoutes();
//        print_r($routes);die;
        $exists = [];
        foreach ($manager->getPermissions() as $name) {
            $name = ArrayHelper::toArray($name);
            if ($name['name'][0] !== '/') {
                continue;
            }
            $route['name'] = $name['name'];
            $route['description'] = $name['description'];
            $route['parent_name'] = $name['parent_name'];
            $exists[] = $route;
            unset($routes[$name['name']]);
        }
        $exists = ArrayHelper::index($exists, null, 'parent_name');

        return [
            'avaliable' => array_keys($routes),
            'assigned' => $exists
        ];
    }

取了‘parent_name’字段,但是数据库表中没有这个字段啊

windhoney commented 7 years ago

文档中漏掉了,这个字段后加的 CREATE TABLE auth_item ( name varchar(64) COLLATE utf8_unicode_ci NOT NULL, type int(11) NOT NULL, description text COLLATE utf8_unicode_ci, rule_name varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, parent_name varchar(30) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '父级名称', data text COLLATE utf8_unicode_ci, created_at int(11) DEFAULT NULL, updated_at int(11) DEFAULT NULL, PRIMARY KEY (name), KEY rule_name (rule_name) USING BTREE, KEY idx-auth_item-type (type) USING BTREE, KEY parent_name (parent_name), CONSTRAINT auth_item_ibfk_1 FOREIGN KEY (rule_name) REFERENCES auth_rule (name) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

wayne798 commented 7 years ago

我现在在auth_item表中添加了parent_name字段,但是我在获取路由列表时提示如下错误

"name": "PHP Notice",
 "message": "Undefined index: parent_name",
"file": "/Applications/XAMPP/xamppfiles/htdocs/api-yii/Source/api/modules/rbac/models/Route.php",
  "line": 109,

也就是上面getRoutes函数中的这个代码

$route['parent_name'] = $name['parent_name'];

请问还需要其他配置么?

wayne798 commented 7 years ago

因为需要做一些修改,在使用该组件时,没有有composer引入,而是把文件单独引入的,这样的话就涉及到一个namespace的问题,因为namespace不一样,是不是还需要修改所有的namespace

wayne798 commented 7 years ago

搞定了,config中components中"authManager" 之前写的是\yii\rbac\DbManager 应该指向你的DbManager 啊,水平太菜了,请见谅。