Role Based Authentication in Yii

composer global require “fxp/composer-asset-plugin:^1.2.0”

yii migrate

In case of yii2-app-base template, from which I have created my application, there is a config/console.php configuration file where the authManager needs to be declared. It is not sufficient to have it in the config/web.php declared only.

In case of yii2-app-advanced the authManager should be declared in console/config/main.php and not in the backend or frontend configuration files

‘components’ => [
. . .
‘authManager’ => [
‘class’ => ‘yii\rbac\DbManager’,
] . . .

and bellow the line in web.php

# add composer




01.Enable Pretty Url #must to work with roles

] ],

‘as access’=>[
] ],

For url correction create .htaccess root/web folder

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

and also enable urlManager in config/web.php

in config/web.php
#default rpute
‘defaultRoute’ => ‘example’,
‘params’ => $params,

Leave a Reply

Your email address will not be published. Required fields are marked *