Blame view

frontend/controllers/SubscribeController.php 903 Bytes
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  <?php
  
  namespace frontend\controllers;
  
  use Yii;
  use yii\web\Controller;
  use common\models\Subscribe;
  use yii\web\HttpException;
  use yii\data\Pagination;
  use yii\web\Response;
  use yii\widgets\ActiveForm;
  
  class SubscribeController extends Controller
  {
  
      public function actionIndex()
      {
  		$model = new Subscribe;
          if (Yii::$app->request->isAjax) {
              Yii::$app->response->format = Response::FORMAT_JSON;
              $model->load(Yii::$app->request->post());
              return ActiveForm::validate($model);
          } else {
              if ($model->load(Yii::$app->request->post()) && $model->save()) {
  
                  Yii::$app->getSession()->setFlash('success', 'Вы успешно подписались на рассылку!');
                  return $this->refresh();
              }
          }
  
          return $this->render('index',['model'=>$model]);        
      }
      
  }