Wednesday 28 September 2016

Allow Access to Specific User role in controller in Yii Framework

Set On Coltroller   


 public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],     'access' => [
                        'class' => \yii\filters\AccessControl::className(),
                        'only' => ['index','create','update','view'],
                        'rules' => [
                            // allow authenticated users
                            [
                                'allow' => true,
                                'roles' => ['@'],
                                'matchCallback' => function ($rule, $action) {
                            if (Yii::$app->user->identity->role==1) {
                                return true;
                            }
                            return false;
                                }
                            ],
                            // everything else is denied
                        ],
                    ],
        ];
    }

No comments:

Post a Comment

Setup VueJS in Laravel

Setup VueJS in Laravel 1. You will need to install javascript dependencies by running the following command on your terminal.      npm i...