SiteController.php 1.2 KB

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