Class app\controllers\SiteController
| Inheritance | app\controllers\SiteController » yii\web\Controller |
|---|---|
| Source Code | https://github.com/yiisoft/yii2-app-basic/blob/master/controllers/SiteController.php |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| actionAbout() | Displays about page. | app\controllers\SiteController |
| actionContact() | Displays contact page. | app\controllers\SiteController |
| actionIndex() | Displays homepage. | app\controllers\SiteController |
| actionLogin() | Login action. | app\controllers\SiteController |
| actionLogout() | Logout action. | app\controllers\SiteController |
| actions() | app\controllers\SiteController | |
| behaviors() | app\controllers\SiteController |
Method Details
Displays about page.
| public string actionAbout ( ) |
public function actionAbout()
{
return $this->render('about');
}
Displays contact page.
| public \yii\web\Response|string actionContact ( ) |
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
Displays homepage.
| public string actionIndex ( ) |
public function actionIndex()
{
return $this->render('index');
}
Login action.
| public \yii\web\Response|string actionLogin ( ) |
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$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',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
| public behaviors ( ) |
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
],
];
}