A
A
AUN2015-03-23 17:21:42
Yii
AUN, 2015-03-23 17:21:42

Yii2 authorization. How to set up correctly?

Hey!
The essence of the problem: there are several modules. All actions in any system somehow come down to CRUD. It is necessary to create user groups through the admin panel, certain rights are assigned to user groups: create read update delete and to which modules.
What is the best way to implement this? For Yii 1.1, I had "self-written", no rbac . Now I want to try it.
First I need to set up config/web.php:

'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'authFile' => '@app/config/rbac.php',
            'defaultRoles' => ['guest'],
        ],

Next, I'll generate rbac.php :
<?php
return [
    'items' =>[
        'admin'=>[
            'type'=>1,
            'name'=>'admin',
            'ruleName' => 'admin',
            'description' => 'Админ',
        ],
        'user'=>[
            'type'=>2,
            'name'=>'user',
            'ruleName' => 'user',
            'description' => 'Пользователь',
        ],
        'guest'=>[
            'type'=>3,
            'name'=>'guest',
            'ruleName' => 'guest',
            'description' => 'Гость',
        ],
    ]
];

Next, apparently, you need to create a rule for the guest and bind specific users to a group of guests. And the other part - to the admins. How?
Ps please, do not throw links to the office. documentation and various blogs, I did not find answers there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2015-03-23
@fornit1917

If you need to edit groups and their rights through the admin panel, then you need to store the rules not in a php file, but in a database. Yii has a DbManager for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question