mdmsoft / yii2-admin

Auth manager for Yii2 (RBAC Manager)
GNU General Public License v3.0
1.16k stars 574 forks source link

Invalid argument supplied for foreach() #87

Closed tiffoknee closed 9 years ago

tiffoknee commented 9 years ago

Invalid argument supplied for foreach()

After updating to yii2 stable and doing a composer update, I am getting the above error

1. in .../vendor/yiisoft/yii2/rbac/PhpManager.php at line 665
                foreach ($item['children'] as $childName) {
                    if (isset($this->items[$childName])) {
                        $this->children[$name][$childName] = $this->items[$childName];
                    }
                }
            }
        }

        foreach ($assignments as $userId => $roles) {
            foreach ($roles as $role) {    <<<<<<<< THIS LINE
                $this->assignments[$userId][$role] = new Assignment([
                    'userId' => $userId,
                    'roleName' => $role,
                    'createdAt' => $assignmentsMtime,
                ]);
            }
        }

I've added the 'as access' section to my common main.php (as below) and removed allowactions from modules > admin

return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'modules' => [
            'admin' => [
            'class' => 'mdm\admin\Module',
            // 'allowActions' => [
            //     'admin/*', // add or remove allowed actions to this list
            //     'user/*'
            // ]
        ],
        'Manage' => [
            'class' => 'common\modules\Manage',
        ],
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'authManager' => [
            'class' => 'yii\rbac\PhpManager', // or use 'yii\rbac\DbManager'
        ]
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false
        ],
        'request' => [
        'enableCookieValidation' => true,
        'enableCsrfValidation' => true,
        'cookieValidationKey' => 'idiweufhaksdjc1243204982374',
    ],
    ],
    'as access' => [
        'class' => 'mdm\admin\components\AccessControl',
        'allowActions' => [
            'admin/*', // add or remove allowed actions to this list
            'user/*'
        ]
    ],
];
mdmunir commented 9 years ago

check file @app/rbac/assignments.php (your assigment file)

tiffoknee commented 9 years ago

thanks mdmunir - it is

<?php
return [
    1 => 'SuperUser',
];
mdmunir commented 9 years ago

value should be

<?php
return [
    1 => [
        'SuperUser',
    ]
];
tiffoknee commented 9 years ago

Thanks, that got it.