[ 'class' => AccessControl::class, 'only' => ['logout'], 'rules' => [ [ 'actions' => ['logout'], 'allow' => true, 'roles' => ['@'], ], ], ], 'verbs' => [ 'class' => VerbFilter::class, 'actions' => [ 'logout' => ['post'], ], ], ]; } public function init(): void { parent::init(); if (Yii::$app->user->can('admin')) { $this->layout = 'admin_main'; }elseif (Yii::$app->user->isGuest) { $this->layout = 'guest_main'; } else { $this->layout = 'main'; } } /** * {@inheritdoc} */ public function actions(): array { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; } /** * Displays homepage. * * @return string */ public function actionIndex(): string { return $this->render('index'); } public function actionEntry(): string { $model = new EntryForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { return $this->render('entry-confirm', ['model' => $model]); } else { return $this->render('entry', ['model' => $model]); } } }