yii2-netdisk/controllers/SiteController.php

87 lines
2.0 KiB
PHP
Raw Normal View History

2013-05-24 22:14:49 +08:00
<?php
namespace app\controllers;
2024-02-09 12:15:09 +08:00
use app\models\EntryForm;
2013-05-24 22:14:49 +08:00
use Yii;
use yii\filters\AccessControl;
2013-05-24 22:14:49 +08:00
use yii\web\Controller;
use yii\filters\VerbFilter;
2013-05-24 22:14:49 +08:00
class SiteController extends Controller
{
/**
2018-02-19 06:29:21 +08:00
* {@inheritdoc}
*/
public function behaviors(): array
2014-03-16 12:46:16 +08:00
{
return [
'access' => [
'class' => AccessControl::class,
2014-03-16 12:46:16 +08:00
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
2014-03-16 12:46:16 +08:00
'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';
}
}
/**
2018-02-19 06:29:21 +08:00
* {@inheritdoc}
*/
public function actions(): array
2014-03-16 12:46:16 +08:00
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
2013-05-24 22:14:49 +08:00
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex(): string
2014-03-16 12:46:16 +08:00
{
return $this->render('index');
}
2013-05-24 22:14:49 +08:00
2024-02-09 12:15:09 +08:00
public function actionEntry(): string
2024-02-09 12:15:09 +08:00
{
$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]);
}
}
}