public function actionGetChildMenu() { $result = ['status' => 'success', 'type' => 'new', 'content' => '']; try { if (!Yii::$app->request->isAjax) { throw new Exception('请求异常'); } $post = Yii::$app->getRequest()->post(); if (!isset($post['menu_id'])) { throw new Exception('缺少参数'); } if ($post['menu_id'] != 0) { $models = Menu::find()->andWhere(['parent_id' => $post['menu_id']])->all(); if (!empty($models)) { $result['content'] = $models; } } else { $result['type'] = 'delete'; } } catch (Exception $exp) { $result = ['status' => 'fail', 'type' => 'new', 'content' => $exp->getMessage()]; } echo Json::encode($result); exit; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::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, 'sort' => $this->sort, 'parent_id' => $this->parent_id, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'menu_name', $this->menu_name])->andFilterWhere(['like', 'menu_url', $this->menu_url]); return $dataProvider; }