Esempio n. 1
0
 /**
  * Lists all Menu models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = Menu::find();
     $query->joinWith(['menuParent' => function ($q) {
         $q->from(Menu::tableName() . ' p');
     }]);
     return new ActiveDataProvider(['query' => $query, 'pagination' => false]);
 }
Esempio n. 2
0
 /**
  * Searching menu
  * @param  array                        $params
  * @return \yii\data\ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuModel::find()->from(MenuModel::tableName() . ' t')->joinWith(['menuParent' => function ($q) {
         $q->from(MenuModel::tableName() . ' parent');
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $sort = $dataProvider->getSort();
     $sort->attributes['menuParent.name'] = ['asc' => ['parent.name' => SORT_ASC], 'desc' => ['parent.name' => SORT_DESC], 'label' => 'parent'];
     $sort->attributes['order'] = ['asc' => ['parent.order' => SORT_ASC, 't.order' => SORT_ASC], 'desc' => ['parent.order' => SORT_DESC, 't.order' => SORT_DESC], 'label' => 'order'];
     $sort->defaultOrder = ['menuParent.name' => SORT_ASC];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent' => $this->parent]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'route', $this->route])->andFilterWhere(['like', 'parent.name', $this->parent_name]);
     return $dataProvider;
 }