Class backend\controllers\SiteController

Inheritancebackend\controllers\SiteController » yii\web\Controller
Source Code https://github.com/yiisoft/yii2-app-advanced/blob/master/backend/controllers/SiteController.php

Site controller

Method Details

Hide inherited methods

actionIndex() public method

Displays homepage.

public string actionIndex ( )

                public function actionIndex()
{
    return $this->render('index');
}

            
actionLogin() public method

Login action.

public string|\yii\web\Response actionLogin ( )

                public function actionLogin()
{
    if (!Yii::$app->user->isGuest) {
        return $this->goHome();
    }
    $this->layout = 'blank';
    $model = new LoginForm();
    if ($model->load(Yii::$app->request->post()) && $model->login()) {
        return $this->goBack();
    }
    $model->password = '';
    return $this->render('login', [
        'model' => $model,
    ]);
}

            
actionLogout() public method

Logout action.

public \yii\web\Response actionLogout ( )

                public function actionLogout()
{
    Yii::$app->user->logout();
    return $this->goHome();
}

            
actions() public method

public void actions ( )

                public function actions()
{
    return [
        'error' => [
            'class' => \yii\web\ErrorAction::class,
        ],
    ];
}

            
behaviors() public method

public void behaviors ( )

                public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::class,
            'rules' => [
                [
                    'actions' => ['login', 'error'],
                    'allow' => true,
                ],
                [
                    'actions' => ['logout', 'index'],
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
        'verbs' => [
            'class' => VerbFilter::class,
            'actions' => [
                'logout' => ['post'],
            ],
        ],
    ];
}