yii-starter-kit / yii2-starter-kit

Yii2 Starter Kit
http://yii2-starter-kit.terentev.net
Other
1.41k stars 646 forks source link

how restrict a user role to backend action #181

Closed zakrot closed 9 years ago

zakrot commented 9 years ago

Hi How restrict a user role such as 'user' to an action of backend I have tried this code in a controller :

public function behaviors() { return [ 'verbs' => [ ... ], 'access' => [ 'class' => \yii\filters\AccessControl::className(), 'rules' => [ [ 'allow' => false, 'actions' => ['index'], 'roles' => ['user'], 'denyCallback' => function () { return Yii::$app->controller->redirect(['/user/default/profile']); } ], ], ], ]; } But noting happened

dungphanxuan commented 9 years ago

Hi, that statert kit is standard for developer can begin application. You shound extend it than change it, Structure of start kit is not hard and you shouldn't change it if you are begin with yii.

trntv commented 9 years ago

Read yii docs about RBAC https://github.com/yiisoft/yii2/blob/master/docs/guide/security-authorization.md

and you can use it: https://github.com/trntv/yii2-starter-kit#globalaccessbehavior