/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Navigation::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, 'user_id' => $this->user_id, 'post_date' => $this->post_date, 'update_date' => $this->update_date, 'parent_id' => $this->parent_id, 'sort' => $this->sort]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'attr_extra', $this->attr_extra])->andFilterWhere(['like', 'display', $this->display]); return $dataProvider; }
private static function getSiteMenuRecrusive($parent) { $items = Navigation::find()->where(['parent_id' => $parent])->orderBy('sort')->asArray()->all(); $result = []; foreach ($items as $item) { $hasItems = self::getSiteMenuRecrusive($item['id']); $getExternalLink = substr($item['detail'], 0, 6); $urlto = Url::to(['/navigation/view', 'id' => $item['id']]); if (strtoupper($getExternalLink) == '{LINK}') { $urlto = substr($item['detail'], 6); } if (count($hasItems) > 0) { $result[] = ['label' => $item['title'], 'url' => $urlto, 'linkOptions' => $item['attr_extra'], 'items' => $hasItems]; } else { $result[] = ['label' => $item['title'], 'url' => $urlto, 'linkOptions' => $item['attr_extra']]; } } return $result; }
/** * Finds the Navigation model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Navigation the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Navigation::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { //$menu = self::getMenu(); $menu = Navigation::getSiteMenuArray(); return $this->render('index', ['menu' => $menu]); }