SiteController.php 1.2 KB

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