Answer the question
In order to leave comments, you need to log in
Yii 2 ban to module?
how to restrict access to a module? so I inherited all the controllers from the base one and wrote in it
<?php
namespace app\modules\video\controllers;
use yii\web\Controller;
class DefaultController extends Controller {
public function actionIndex()
{
return $this->render('index');
}
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['*'],
'rules' => [
[
'actions' => ['*'],
'allow' => true,
'roles' => ['@'],
// 'roles' => ['admin'],
],
],
],
];
}
}
Answer the question
In order to leave comments, you need to log in
you can add
to \modules\video\Module.php
public function beforeAction($action)
{
if (!parent::beforeAction($action))
{
return false;
}
if (!Yii::$app->user->isGuest)
{
return true;
}
else
{
Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
//для перестраховки вернем false
return false;
}
}
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language' => 'ru',
'timezone' => 'Asia/Yekaterinburg',
'modules' => [
'user' => [
'class' => 'amnah\yii2\user\Module',
],
'video' => [
'class' => 'app\modules\video\Module',
'as access' => [ // if you need to set access
'class' => 'yii\filters\AccessControl',
'rules' => [
[
'allow' => true,
'roles' => ['@'] // all auth users
],
]
],
],
],
I don't remember exactly right now. But something like:
'rules' => [
[
'actions' => ['login', 'error'], // тут список разрешенных экшенов
'allow' => true,
'roles' => ['@'],
],
[
'actions' => ['*'],
'allow' => true,
'roles' => ['admin'],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question