PHP code example of yidas / yii2-access-router
1. Go to this page and download the library: Download yidas/yii2-access-router library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yidas / yii2-access-router example snippets
return [
'bootstrap' => ['log', 'access'],
'components' => [
'access' => [
'class' => 'yidas\filters\AccessRouter',
'except' => ['site/login', 'site/register'],
'denyCallback' => function() {
return Yii::$app->response->redirect(['/site/login']);
},
],
// ...
],
// ...
];
'access' => [
'class' => 'yidas\filters\AccessRouter',
'except' => ['site/login'], //`site/login` is the login page which can not bypass user authorization
],
'access' => [
'class' => 'yidas\filters\AccessRouter',
'except' => ['site/login', 'site/register'],
'httpAuth' => [
'enable' => true,
'denyCallback' => function() {
$response = Yii::$app->response;
$response->statusCode = 401;
$response->format = \yii\web\Response::FORMAT_JSON;
$response->data = ['message' => 'Access Denied'];
return $response->send();
},
],
],
'access' => [
'class' => 'yidas\filters\AccessRouter',
'except' => ['site/login', 'site/register'],
'httpLogin' => [
'enable' => true,
'method' => 'post'
'only' => ['site/login'],
// 'key' => 'access_token',
],
],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'enableCsrfValidation' => false,
],
'bootstrap' => ['log', 'access'],
'components' => [
'access' => [
'class' => 'yidas\filters\AccessRouter',
'except' => ['*'], // Equal to comment out
],
// ...
],
'as beforeRequest' => [
'class' => 'yii\filters\AccessControl',
'rules' => [
[
'allow' => true,
'actions' => ['login'],
],
[
'allow' => true,
'roles' => ['@'],
],
],
'denyCallback' => function () {
return Yii::$app->response->redirect(['site/login']);
},
],