更新功能

This commit is contained in:
2020-02-18 17:24:06 +08:00
parent 0d7635b972
commit 4c036db815
18 changed files with 134 additions and 144 deletions

View File

@@ -43,7 +43,9 @@ class Menu extends Admin {
/**
* @title 编辑菜单字段
*/
public function editable($name = null, $value = null, $pk = null) {
public function editable() {
$data = $this->request->param();
if ($name && ($value != null || $value != '') && $pk) {
db('Menu')->where(array('id' => $pk))->setField($name, $value);
}
@@ -67,18 +69,20 @@ class Menu extends Admin {
return $this->error('新增失败');
}
} else {
$this->assign('info', array('pid' => input('pid')));
$menus = db('Menu')->select();
$tree = new \com\Tree();
$menus = MenuM::select()->toArray();
$tree = new \sent\tree\Tree();
$menus = $tree->toFormatTree($menus);
if (!empty($menus)) {
$menus = array_merge(array(0 => array('id' => 0, 'title_show' => '顶级菜单')), $menus);
} else {
$menus = array(0 => array('id' => 0, 'title_show' => '顶级菜单'));
}
$this->assign('Menus', $menus);
$this->setMeta('新增菜单');
$this->data = [
'info' => ['pid' => $this->request->param('pid', 0)],
'Menus' => $menus
];
return $this->fetch('edit');
}
}
@@ -89,31 +93,34 @@ class Menu extends Admin {
*/
public function edit($id = 0) {
if ($this->request->isPost()) {
$Menu = model('Menu');
$data = input('post.');
if ($Menu->save($data, array('id' => $data['id'])) !== false) {
session('admin_menu_list', null);
//记录行为
action_log('update_menu', 'Menu', $data['id'], session('user_auth.uid'));
return $this->success('更新成功', Cookie('__forward__'));
$data = $this->request->post();
$result = MenuM::update($data, ['id' => $data['id']]);
if (false !== $result) {
return $this->success('更新成功', '/admin/menu/index');
} else {
return $this->error('更新失败');
}
} else {
$info = array();
$info = [];
/* 获取数据 */
$info = db('Menu')->field(true)->find($id);
$menus = db('Menu')->field(true)->select();
$tree = new \com\Tree();
$info = MenuM::find($id);
$menus = MenuM::select()->toArray();
$tree = new \sent\tree\Tree();
$menus = $tree->toFormatTree($menus);
$menus = array_merge(array(0 => array('id' => 0, 'title_show' => '顶级菜单')), $menus);
$this->assign('Menus', $menus);
if (false === $info) {
return $this->error('获取后台菜单信息错误');
}
$this->assign('info', $info);
$this->setMeta('编辑后台菜单');
$this->data = [
'Menus' => $menus,
'info' => $info
];
return $this->fetch();
}
}