Class backend\controllers\SiteController
| Inheritance | backend\controllers\SiteController » yii\web\Controller |
|---|---|
| Source Code | https://github.com/yiisoft/yii2-app-advanced/blob/master/backend/controllers/SiteController.php |
Site controller
Public Methods
| Method | Description | Defined By |
|---|---|---|
| actionIndex() | Displays homepage. | backend\controllers\SiteController |
| actionLogin() | Login action. | backend\controllers\SiteController |
| actionLogout() | Logout action. | backend\controllers\SiteController |
| actions() | backend\controllers\SiteController | |
| behaviors() | backend\controllers\SiteController |
Method Details
Displays homepage.
| public string actionIndex ( ) |
public function actionIndex()
{
return $this->render('index');
}
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,
]);
}
Logout action.
| public \yii\web\Response actionLogout ( ) |
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
| public actions ( ) |
public function actions()
{
return [
'error' => [
'class' => \yii\web\ErrorAction::class,
],
];
}
| public 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'],
],
],
];
}