Exemplo n.º 1
0
 public function actionManagerole()
 {
     $request = Yii::$app->request;
     if ($request->isGet) {
         // 接受更改页面
         $data['role'] = Adminrole::find()->where(['id' => $request->get('id')])->asArray()->one();
         // 处理权限为数组
         $data['role']['root'] = explode('|', $data['role']['root']);
         // 拿出深度是0的菜单
         $data['menu'] = Adminmenu::find()->where(['deep' => 0, 'statu' => 1])->orderBy(['sort' => SORT_ASC])->asArray()->all();
         // 拿出深度是1的菜单
         foreach ($data['menu'] as $key1 => $value1) {
             $tmp = Adminmenu::find()->where(['father' => $value1['id'], 'statu' => 1])->orderBy(['sort' => SORT_ASC])->asArray()->all();
             // 遍历拿出末级菜单
             foreach ($tmp as $key2 => $value2) {
                 $tmp[$key2]['child'] = Adminmenu::find()->where(['father' => $value2['id'], 'statu' => 1])->orderBy(['sort' => SORT_ASC])->asArray()->all();
             }
             $data['menu'][$key1]['child'] = $tmp;
         }
         return $this->renderPartial('managerole', $data);
     }
 }
Exemplo n.º 2
0
 private function normalMenu($root)
 {
     $third = explode("|", $root);
     $third = Adminmenu::find()->where(['id' => $third])->orderBy(['sort' => SORT_ASC])->asArray()->all();
     $secend = [];
     foreach ($third as $value) {
         if (!in_array($value['father'], $secend)) {
             array_push($secend, $value['father']);
         }
     }
     $secend = Adminmenu::find()->where(['id' => $secend])->orderBy(['sort' => SORT_ASC])->asArray()->all();
     $first = ['child' => []];
     foreach ($secend as $value) {
         if (!in_array($value['father'], $first)) {
             array_push($first, $value['father']);
         }
     }
     $data['mideMenus'] = Adminmenu::find()->where(['id' => $first])->orderBy(['sort' => SORT_ASC])->asArray()->all();
     // 二三菜单合并
     foreach ($secend as $key => $sec) {
         $tmp = [];
         foreach ($third as $thd) {
             if ($thd['father'] == $sec['id']) {
                 array_push($tmp, $thd);
             }
         }
         $secend[$key]['child'] = $tmp;
     }
     $data['secendMenus'] = $secend;
     return $data;
 }
Exemplo n.º 3
0
 public function actionEditmenu($id = null)
 {
     if (!$id) {
         // 接受数据
         $data = Yii::$app->request->post("data");
         // 检测数据
         $res = $this->check($data);
         if ($res['statu'] == 'success') {
             // 查询父菜单深度
             if ($data['father'] != 0) {
                 $father = Adminmenu::find()->select(['deep'])->where(['id' => $data['father']])->asArray()->one();
             } else {
                 $father['deep'] = -1;
             }
             $newMenu = Adminmenu::find()->where(['id' => $data['id']])->one();
             $newMenu->name = $data['name'];
             $newMenu->father = $data['father'];
             $newMenu->deep = $father['deep'] + 1;
             $newMenu->url = $data['url'];
             $newMenu->statu = $data['statu'];
             if ($newMenu->save()) {
                 $res['des'] = "菜单更改成功!";
                 $res['jump'] = Url::toRoute('/admin/menu/manage');
             } else {
                 $res['des'] = "菜单更改失败!数据库错误!";
                 $res['statu'] = "error";
             }
         }
         return json_encode($res);
     } else {
         // 取出该菜单信息
         $data['edited'] = Adminmenu::find()->where(['id' => $id])->asArray()->one();
         $data['menus'] = Adminmenu::find()->where(['deep' => 0])->orderBy(['sort' => SORT_ASC])->asArray()->all();
         // 取出二级菜单
         foreach ($data['menus'] as $key => $value) {
             $tmp = Adminmenu::find()->where(['father' => $value['id']])->orderBy(['sort' => SORT_ASC])->asArray()->all();
             $data['menus'][$key]['child'] = $tmp;
         }
         return $this->renderPartial('editmenu', $data);
     }
 }