Blame view

frontend/controllers/ServiceController.php 1.6 KB
aedc35b5   Anastasia   - load scg to logo
1
2
3
4
5
6
7
8
9
10
11
  <?php
      /**
       * Created by PhpStorm.
       * User: stes
       * Date: 29.05.18
       * Time: 9:51
       */
      
      namespace frontend\controllers;
      
      use common\models\Service;
43a24059   Anastasia   - servives
12
      use yii\db\ActiveQuery;
aedc35b5   Anastasia   - load scg to logo
13
14
15
16
17
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
  
      class ServiceController extends Controller
      {
aedc35b5   Anastasia   - load scg to logo
18
19
20
21
22
23
24
25
          public function actionView($id){
              $model = $this->findModel($id);
              if ($model->parent_id == null){
                 $others = Service::find()->where(['parent_id' => $model->id])->all();
              }else{
                  $others = Service::find()->where(['parent_id' => $model->parent_id])->all();
              }
              
43a24059   Anastasia   - servives
26
              $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
aedc35b5   Anastasia   - load scg to logo
27
28
29
30
31
32
33
34
35
              return $this->render('view', [
                  'model' => $model,
                  'others'=> $others
              ]);
          }
          
          public function findModel($id){
              $model = Service::find()
                              ->where(['id' => $id, 'status' => true])
43a24059   Anastasia   - servives
36
37
38
39
40
                              ->with(['language.alias', 'image',  'prices' => function (ActiveQuery $query){
                                  $query->where(['status' => true])->orderBy('sort');
                              }, 'comments' => function (ActiveQuery $query){
                                  $query->where(['status' => true]);
                              }])->one();
aedc35b5   Anastasia   - load scg to logo
41
42
43
44
45
46
              if (empty($model)){
                  throw new NotFoundHttpException('Model not found');
              }
              return $model;
          }
      }