SiteController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use app\models\LoginForm;
  6. use app\models\ContactForm;
  7. class SiteController extends Controller
  8. {
  9. public function actions()
  10. {
  11. return array(
  12. 'error' => array(
  13. 'class' => 'yii\web\ErrorAction',
  14. ),
  15. 'captcha' => array(
  16. 'class' => 'yii\captcha\CaptchaAction',
  17. 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  18. ),
  19. );
  20. }
  21. public function actionIndex()
  22. {
  23. return $this->render('index');
  24. }
  25. public function actionLogin()
  26. {
  27. $model = new LoginForm();
  28. if ($model->load($_POST) && $model->login()) {
  29. return $this->goHome();
  30. } else {
  31. return $this->render('login', array(
  32. 'model' => $model,
  33. ));
  34. }
  35. }
  36. public function actionLogout()
  37. {
  38. Yii::$app->user->logout();
  39. return $this->goHome();
  40. }
  41. public function actionContact()
  42. {
  43. $model = new ContactForm;
  44. if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
  45. Yii::$app->session->setFlash('contactFormSubmitted');
  46. return $this->refresh();
  47. } else {
  48. return $this->render('contact', array(
  49. 'model' => $model,
  50. ));
  51. }
  52. }
  53. public function actionAbout()
  54. {
  55. return $this->render('about');
  56. }
  57. }