Commit 2032cb188faa9854efa32068a75da20549553b80
1 parent
f1a0d1e0
- services menu
Showing
2 changed files
with
14 additions
and
3 deletions
Show diff stats
frontend/controllers/ServiceController.php
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | use common\models\Service; |
| 12 | 12 | use yii\db\ActiveQuery; |
| 13 | + use yii\db\Query; | |
| 13 | 14 | use yii\web\Controller; |
| 14 | 15 | use yii\web\NotFoundHttpException; |
| 15 | 16 | |
| ... | ... | @@ -18,9 +19,11 @@ |
| 18 | 19 | public function actionView($id){ |
| 19 | 20 | $model = $this->findModel($id); |
| 20 | 21 | if ($model->parent_id == null){ |
| 21 | - $others = Service::find()->where(['parent_id' => $model->id])->all(); | |
| 22 | + $others = Service::find()->where(['parent_id' => $model->id])->with('services')->all(); | |
| 23 | + }elseif ($model->level == 1){ | |
| 24 | + $others = Service::find()->where(['parent_id' => $model->parent_id])->with('services')->all(); | |
| 22 | 25 | }else{ |
| 23 | - $others = Service::find()->where(['parent_id' => $model->parent_id])->all(); | |
| 26 | + $others = Service::find()->where(['parent_id' => (new Query())->select('parent_id')->from('service')->where(['id' => $model->parent_id])])->with('services')->all(); | |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | 29 | $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body); | ... | ... |
frontend/views/service/view.php
| ... | ... | @@ -28,7 +28,15 @@ |
| 28 | 28 | <div class="style service-list-wr"> |
| 29 | 29 | <ul> |
| 30 | 30 | <?php foreach ($others as $service){?> |
| 31 | - <li <?=($model->id == $service->id ? 'class="active"' : '')?>><a href="<?=Url::to(['alias' => $service->alias])?>"><?=$service->title?></a></li> | |
| 31 | + <li class="<?=(($model->id == $service->id and $model->level != 2) ? 'active' : '')?> <?=(($model->parent_id == $service->id and $model->level == 2) ? 'active2' : '')?> <?=(!empty($service->services) ? 'has-list' : '')?>"><a href="<?=Url::to(['alias' => $service->alias])?>"><?=$service->title?></a> | |
| 32 | + <?php | |
| 33 | + if (($model->id == $service->id or $model->parent_id == $service->id) and !empty($service->services))?> | |
| 34 | + <ul> | |
| 35 | + <?php foreach ($service->services as $item){?> | |
| 36 | + <li class="<?=($model->id == $item->id ? 'active' : '')?>"><a href="<?=Url::to(['alias' => $item->alias])?>"><?=$item->title?></a></li> | |
| 37 | + <?php }?> | |
| 38 | + </ul> | |
| 39 | + </li> | |
| 32 | 40 | <?php }?> |
| 33 | 41 | </ul> |
| 34 | 42 | </div> | ... | ... |