Blame view

controllers/SiteController.php 1.42 KB
2049c43e   Alexey Boroda   first commit
1
  <?php
9568083b   Alexey Boroda   -Backend left
2
3
4
      
      namespace app\controllers;
      
2929939c   Alexey Boroda   -Kind of ready
5
      use app\models\Subscribe;
9568083b   Alexey Boroda   -Backend left
6
7
8
9
      use yii\web\Controller;
      use yii\filters\VerbFilter;
      
      class SiteController extends Controller
2049c43e   Alexey Boroda   first commit
10
      {
9568083b   Alexey Boroda   -Backend left
11
12
13
14
15
16
17
18
19
20
21
22
23
          public $enableCsrfValidation = false;
          
          /**
           * {@inheritdoc}
           */
          public function behaviors()
          {
              return [
                  'verbs' => [
                      'class'   => VerbFilter::className(),
                      'actions' => [
                          'logout'    => [ 'post' ],
                          'subscribe' => [ 'post' ],
2049c43e   Alexey Boroda   first commit
24
25
                      ],
                  ],
9568083b   Alexey Boroda   -Backend left
26
              ];
2049c43e   Alexey Boroda   first commit
27
          }
9568083b   Alexey Boroda   -Backend left
28
29
30
31
          
          public function actionSubscribe()
          {
              if (\Yii::$app->request->isPost) {
2929939c   Alexey Boroda   -Kind of ready
32
33
34
35
36
37
38
39
40
41
42
43
                  $model = new Subscribe();
                  $model->load(\Yii::$app->request->post(), '');
                  $model->time = time();
                  $model->domain = \Yii::$app->request->getHostInfo();
                  
                  if ($model->save()) {
                      return true;
                  } else {
                      \Yii::error('Subscribtion didnt saved');
                      
                      return false;
                  }
9568083b   Alexey Boroda   -Backend left
44
              }
2049c43e   Alexey Boroda   first commit
45
          }
9568083b   Alexey Boroda   -Backend left
46
47
48
49
50
51
52
53
54
          
          /**
           * Displays homepage.
           *
           * @return string
           */
          public function actionIndex()
          {
              return $this->render('index');
2049c43e   Alexey Boroda   first commit
55
          }
2049c43e   Alexey Boroda   first commit
56
      }