Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'view' => $this->view, 'position' => $this->position, 'status' => $this->status, 'created' => $this->created, 'updated' => $this->updated]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public static function getMenu($parent_id = null, $level = 0)
 {
     if (empty($parent_id)) {
         $parent_id = null;
     }
     $categories = Category::find()->where(['parent_id' => $parent_id])->all();
     $list = array();
     foreach ($categories as $category) {
         //$category->title = str_repeat(' - ', $level) . $category->title;
         //$list[]['label'] = $category->title;
         //$list[]['alias'] = $category->alias;
         $list[] = array('label' => $category->title, 'url' => $category->alias);
         $list = ArrayHelper::merge($list, self::getMenu($category->id, $level + 1));
     }
     return $list;
 }