<?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'],
],
],
],
];
}
}
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
],
]
],
],
],
'rules' => [
[
'actions' => ['login', 'error'], // тут список разрешенных экшенов
'allow' => true,
'roles' => ['@'],
],
[
'actions' => ['*'],
'allow' => true,
'roles' => ['admin'],
],
],