douya2982 2019-03-27 05:50
浏览 92

yii2admin override在null上调用成员函数getRoles():不从配置文件中读取authManager

Error: Call to a member function getRoles() on null

comes from: yii2-admin\models\searchs\AuthItem.php

on line 75:

public function search($params)
{
    /* @var \yiibac\Manager $authManager */
    $authManager = Configs::authManager();
    if ($this->type == Item::TYPE_ROLE) {
here->  $items = $authManager->getRoles();
    } else {

This is because of yii2-admin\components\configs.php:

on line 148:

public static function instance()
{
    if (self::$_instance === null) {
        $type = ArrayHelper::getValue(Yii::$app->params, 'mdm.admin.configs', []);
        if (is_array($type) && !isset($type['class'])) {
            $type['class'] = static::className();
        }

        return self::$_instance = Yii::createObject($type);
    }

here->  return self::$_instance;
}

it returns a config object where 'authManager' is null

According to: Yii2 RBAC DbManager error Call to a member function getRole() on null

and

https://www.yiiframework.com/doc/guide/2.0/en/security-authorization#configuring-rbac-manager

All that is necessary for the yii2-advanced-app is to add the following:

'authManager' => [
            'class' => 'common\components\extendedbac\DbManager',           
            'cache' => 'cache',
        ],

to common\config\main.php under components array

That was already there and does not seem to effect the config from rbac. In addition I have tried adding authManager to console, frontend and backend config files with no effect.

Expected result: 'authManager' => 'DbManager or something'

Actual result: 'authManager' => null

The yii2 rbac config file loads in the db connection correctly, but authManager is always null.

This is a problem when using the yii2admin rbac management extention, but not when using yii2-advanced-app in general as the advanced app uses \Yii::$app->authManager and not yii2 rbac Configs::authManager

Any help or pointers would be greatly appreciated. Thank you.

展开全部

  • 写回答

1条回答 默认 最新

  • doujingtang6580 2019-03-27 06:58
    关注

    (Based on the comment by csminb)

    The code was failing on DbManager's implementation of yiibac\ManagerInterface.

    Dbmanager which is extended in our program, is already extended from BaseManager which in turn implements ManagerInterface.

    Since DbManager and BaseManager are extended they pointed to the extended ManagerInterface which never needed extending in the first place. :-(

    So the fix is to change BaseManager.php from:

    abstract class BaseManager extends Component implements ManagerInterface
    

    to:

    abstract class BaseManager extends Component implements \yiibac\ManagerInterface
    

    it is important to note that these extended files are in the folder: namespace common\components\extendedbac;

    Thank you again @csminb and stackoverflow for being so very helpful.

    评论
    编辑
    预览

    报告相同问题?

    悬赏问题

    • ¥15 基于stc89c52单片机的延时小夜灯
    • ¥15 VQAV2现在都是怎么做evaluation的啊
    • ¥20 C#添加、更新MYSQL数据库问题
    • ¥15 ambari部署hadoop集群中的问题
    • ¥15 分析照片像素时,怎样剔除照片背景像素
    • ¥15 Cytoscape导入问题
    • ¥15 关于#lstm#的问题:我想利用一个地方的四组数据来预测第五组数据,如果想预测出另外一个地方(只有前四组数据)的第五组数据(相关搜索:预测模型)
    • ¥15 windows窗口外边框分区是什么?(qt应用)
    • ¥15 使用lightgbm框架,对糖尿病趋势进行预测。
    • ¥30 给出MySQL数据库workbench代码
    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部