/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MenuPoint::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'menu' => $this->menu, 'page_id' => $this->page_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'link', $this->link]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getMenuPoint() { return $this->hasOne(MenuPoint::className(), ['id' => 'menu_point_id']); }
<?php $this->beginBody(); ?> <div id="page"> <header> <?php NavBar::begin(['brandLabel' => 'My Company', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse']]); echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => [['label' => 'Home', 'url' => ['/site/index']], ['label' => 'About', 'url' => ['/site/about']], ['label' => 'Contact', 'url' => ['/site/contact']], Yii::$app->user->isGuest ? ['label' => 'Login', 'url' => ['/site/login']] : ['label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']]]]); NavBar::end(); ?> </header> <div class="container"> <?php echo \yii\widgets\Menu::widget(['options' => ['class' => ''], 'items' => \app\modules\page\models\MenuPoint::getMenuItems(), 'activateParents' => true]); ?> <?php echo $content; ?> </div> <div id="push"></div> </div> <footer> </footer> <?php $this->endBody(); ?>
/** * Finds the MenuPoint model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MenuPoint the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MenuPoint::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }