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() #94

Closed ipppinto closed 9 years ago

ipppinto commented 9 years ago

Hi,

I have this error and I don't know why (different of issue #86)

in /var/www/vhosts/vps101842.ovh.net/cmcintranet.ippinto.ovh/vendor/yiisoft/yii2/rbac/PhpManager.php at line 641

    $this->assignments = [];
    $this->items = [];

    $items = $this->loadFromFile($this->itemFile);
    $itemsMtime = @filemtime($this->itemFile);
    $assignments = $this->loadFromFile($this->assignmentFile);
    $assignmentsMtime = @filemtime($this->assignmentFile);
    $rules = $this->loadFromFile($this->ruleFile);

    foreach ($items as $name => $item) {  <<-- This line -->
        $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();

        $this->items[$name] = new $class([
            'name' => $name,
            'description' => isset($item['description']) ? $item['description'] : null,
            'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null,
            'data' => isset($item['data']) ? $item['data'] : null,
            'createdAt' => $itemsMtime,
            'updatedAt' => $itemsMtime,

Thank you

ipppinto commented 9 years ago

The problem is that I create the rbac folder with files

mdmunir commented 9 years ago

what content of file '@app/rbac/items.php';

ipppinto commented 9 years ago

This is the problem. I don't have nothing.

FantomX1-github commented 6 years ago

When I removed custom items, assignment and ruleFile paths from config, removed rbac directory and re-added configs but access right data creation put into own rbacController console command which I run, containig createRole, add, createPermission commands. Mine files got filled and in the end from code

        mkdir(Yii::getAlias("@app/rbac"));
        $auth = Yii::$app->authManager;
        $admin = $auth->createRole('admin');
        $auth->add($admin);

        $viewOwnRequest = $auth->createPermission('viewOwnRequest');
        $auth->add($viewOwnRequest);

        $auth->addChild($admin, $viewOwnRequest);

resulted in

return [
    'admin' => [
        'type' => 1,
        'children' => [
            'viewOwnRequest',
        ],
    ],
    'viewOwnRequest' => [
        'type' => 2,
    ],
];