Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 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;
 }