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