*/ class MenuController extends AuthController { public $modelClass = Menu::class; /** * @doc-name 菜单列表 */ public function actionList() { $user=\Yii::$app->user->identity; $rule_id=AuthRole::find()->select(['rule_id'])->where(['role_id'=>$user->role])->column(); $AuthRule_path=AuthRule::find()->select(['path'])->where(['in','id',$rule_id])->andWhere(['type'=>1])->column(); $menu2s = Menu::find()->where(['in','menuUrl',$AuthRule_path])->andWhere(['hidden'=>0])->orderBy(['sort'=>SORT_ASC])->asArray()->all(); return ArrayHelper::itemsMerge($menu2s,'','menuUrl','parentPath','children'); } public function actionSave(){ $menuUrl = $this->post('menuUrl'); $model = Menu::findOne($menuUrl); if(!$model){ $model = new Menu(); } $model->load($this->post()); if( $model->load($this->post(),'') && $model->save()){ return $model->getAttributes(); }else{ throw new Exception("参数不对"); } } public function actionDel(){ $menuUrl = $this->post('menuUrl'); $model = Menu::findOne($menuUrl); if (!$model) throw new \yii\db\Exception('菜单不存在'); if($model->delete()){ Menu::updateAll(['parentPath'=>''],['parentPath'=>$menuUrl]); } return ['删除成功']; } /** * @doc-name 编辑菜单 */ public function actionEdit() { $data= $this->post(); $menuUrl = $this->post('menuUrl'); $model = Menu::findOne($menuUrl); if (!$model) throw new \yii\db\Exception('菜单不存在'); $model->attributes=$data; $model->saveOrFail(); return ['编辑成功']; } }