Accesscontrol And Roles

Hi guys. Need some advice.

Suppose I want to create simple auth system, without using RBAC, but with a couple of roles besides built-in “?’” and “@”, so that I can use


public function behaviors()

{

    return [

        'access' => [

            'class' => 'yii\web\AccessControl',

            'rules' => [

                [

                    'allow' => true,

                    'roles' => ['moderator', 'admin'],

                ],

            ],

        ],

    ];

}

The only thing I need is restricting access to some actions based on user roles.

Where’s the best place to add a couple of code lines?

Should I extend user component, overriding checkAccess? should I create my own PhpManager? should I stick with default RBAC?

And where and how should I ‘store’ current user’s role, aquired from DB? (example: in session, during user’s init())

Override AccessRule::matchRole() and configure AccessControl::ruleConfig

Oh. thanks for a fast answer.

Is this right syntax?




public function behaviors()

        {

                return [

                    'access' => [

                        'class' => \yii\web\AccessControl::className(),

                        'ruleConfig' => [

                            'class' => 'app\components\AccessRule'

                        ],

                    ],

                ];

      }



Yes. See this post for full example.