Blame view

frontend/controllers/AjaxController.php 1.37 KB
7f87d6f9   Yarik   Modals.
1
2
3
4
5
6
  <?php
  
  namespace frontend\controllers;
  
  use common\models\Feedback;
  use yii\web\Controller;
10b789ee   Administrator   big commti
7
  use \common\modules\product\widgets\specialProducts;
7f87d6f9   Yarik   Modals.
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
35
  class AjaxController extends Controller
  {
      public function actionFeedback() {
          $response = \Yii::$app->response;
          $response->format = $response::FORMAT_JSON;
          $request = \Yii::$app->request;
          $model = new Feedback([
              'scenario' => Feedback::SCENARIO_FEEDBACK,
          ]);
          if($model->load($request->post())) {
              if($model->validate()) {
                  $model->save(false);
                  return [
                      'result' => 'Запрос успешно отправлен.',
                  ];
              } else {
                  return [
                      'error' => 'Validation failed',
                      'result' => [
                          'errors' => $model->getFirstErrors(),
                      ],
                  ];
              }
          }
          $response->statusCode = 400;
          $response->statusText = 'Empty request';
          return ['error' => 'Empty request'];
      }
10b789ee   Administrator   big commti
36
37
38
39
40
41
42
43
44
45
46
47
48
  
  
      public function actionNew(){
          return specialProducts::widget(['type' => 'new']);
      }
  
      public function actionTop(){
          return specialProducts::widget(['type' => 'top']);
      }
  
      public function actionProm(){
          return specialProducts::widget(['type' => 'promo']);
      }
7f87d6f9   Yarik   Modals.
49
  }