SiteController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 'captcha' => array(
  13. 'class' => 'yii\web\CaptchaAction',
  14. 'fixedVerifyCode' => YII_ENV_DEV ? 'testme' : null,
  15. ),
  16. );
  17. }
  18. public function actionIndex()
  19. {
  20. return $this->render('index');
  21. }
  22. public function actionLogin()
  23. {
  24. $model = new LoginForm();
  25. if ($model->load($_POST) && $model->login()) {
  26. return $this->redirect(array('site/index'));
  27. } else {
  28. return $this->render('login', array(
  29. 'model' => $model,
  30. ));
  31. }
  32. }
  33. public function actionLogout()
  34. {
  35. Yii::$app->user->logout();
  36. return $this->redirect(array('site/index'));
  37. }
  38. public function actionContact()
  39. {
  40. $model = new ContactForm;
  41. if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
  42. Yii::$app->session->setFlash('contactFormSubmitted');
  43. return $this->refresh();
  44. } else {
  45. return $this->render('contact', array(
  46. 'model' => $model,
  47. ));
  48. }
  49. }
  50. public function actionAbout()
  51. {
  52. return $this->render('about');
  53. }
  54. }