Shaig Khaligli
Shaig Khaligli

Reputation: 5485

Yii2 adminpanel authorization

I want my project`s program should be like this:
I have divided admin into 2 groups

  1. Mainadmin
  2. Secondadmin

1) There is a mainadmin and a number of secondadmins. Main admin can create, edit secondadmins and while creating and editing, mainadmin should be able to create passwords and usernames for secondadmins.

2) When Secondadmins will login they should see only a page.With this page secondadmins can create their child admins and give them their own usernames and passwords.

Upvotes: 2

Views: 88

Answers (1)

Sageth
Sageth

Reputation: 1112

See Yii2 Roles to build your own way to restrict access and Access Control class

You can do something like that:

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'allow' => true,
                    'actions' => ['login', 'mainpage'],
                    'roles' => ['secondadmin'],
                ],
                [
                    'allow' => true,
                    'roles' => ['mainadmin'],
                ],
            ],
        ],
    ];
}

In this controller, mainadmin can do any action, but second admin only can use login and mainpage actions.

Upvotes: 3

Related Questions