ServiceController.php 1.23 KB
<?php
    /**
     * Created by PhpStorm.
     * User: stes
     * Date: 29.05.18
     * Time: 9:51
     */
    
    namespace frontend\controllers;
    
    use common\models\Service;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;

    class ServiceController extends Controller
    {
        public function actionIndex(){
        
        }
        
        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();
            }
            
            return $this->render('view', [
                'model' => $model,
                'others'=> $others
            ]);
        }
        
        public function findModel($id){
            $model = Service::find()
                            ->where(['id' => $id, 'status' => true])
                            ->with(['language.alias', 'image', 'prices'])->one();
            if (empty($model)){
                throw new NotFoundHttpException('Model not found');
            }
            return $model;
        }
    }