public function init() { parent::init(); if ($this->area_code === null) { $this->menu_items = null; } else { $is_area_id_exists = CmsMenuArea::find()->where(['area_code' => $this->area_code, 'status' => 1])->exists(); if ($is_area_id_exists) { $menu_area = CmsMenuArea::find()->where(['area_code' => $this->area_code])->select('area_id')->one(); $this->menu_items['status'] = 'success'; $this->menu_items['menus'] = $this->getActiveMenus($menu_area->area_id); $this->menu_items['status_message'] = 'Menu details fetched successfully'; } else { $this->menu_items['status'] = 'failed'; $this->menu_items['menus'] = array(); $this->menu_items['status_message'] = 'Invalid Area Code / Area Code Not Exists'; } } }
<?php use yii\helpers\Html; use caritor\cms\models\CmsMenuArea; /* @var $this yii\web\View */ /* @var $model caritor\cms\models\CmsMenu */ $this->title = 'Manage Menu'; $this->params['breadcrumbs'][] = ['label' => 'Manage Menu', 'url' => ['selectarea']]; // $this->params['breadcrumbs'][] = ['label' => $model->menu_id, 'url' => ['view', 'id' => $model->menu_id]]; // $this->params['breadcrumbs'][] = 'Update'; ?> <div class="cms-menu-update"> <h3><?php echo Html::encode($this->title); ?> </h3> <?php echo $this->render('select_area', ['model' => $model, 'items' => CmsMenuArea::find()->select(['area_id', 'name'])->where(['status' => '1'])->asArray()->all()]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getArea() { return $this->hasOne(CmsMenuArea::className(), ['area_id' => 'area_id']); }
/** * Finds the CmsMenuArea model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CmsMenuArea the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CmsMenuArea::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }