Blogger Information
Blog 42
fans 0
comment 0
visits 15729
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0909 菜单列表增删查改
小言
Original
425 people have browsed it

菜单列表增删查改

增 改

  1. public function MenuAdd(){
  2. $post = input('post.');
  3. if(empty($post['label'])){
  4. $arr = [
  5. 'code' => 1,
  6. 'msg' => '请输入菜单名',
  7. ];
  8. echo json_encode($arr);
  9. exit;
  10. }
  11. if(preg_match_all("/[#$%^&*@ ]/",$post['label']) > 0){
  12. $arr = [
  13. 'code' => 1,
  14. 'msg' => '菜单名不能不特殊符号',
  15. ];
  16. echo json_encode($arr);
  17. exit;
  18. }
  19. $data = [
  20. 'label' => $post['label'],
  21. 'sort' => $post['sort'],
  22. 'type' => $post['type'],
  23. 'src' => $post['type']==0?'':$post['src'],
  24. 'icon_class' => $post['icon_class'],
  25. 'status' => $post['status']
  26. ];
  27. /* 添加 */
  28. if($post['mid'] == 0){
  29. $ret = Db::table('yj_admin_menu')->insert($data);
  30. }else{
  31. /* 修改 */
  32. $ret = Db::table('yj_admin_menu')->where('mid',$post['mid'])->update($data);
  33. }
  34. if(empty($ret)){
  35. $arr = [
  36. 'code' => 1,
  37. 'msg' => '失败',
  38. ];
  39. echo json_encode($arr);
  40. exit;
  41. }else{
  42. $arr = [
  43. 'code' => 0,
  44. 'msg' => '成功',
  45. ];
  46. echo json_encode($arr);
  47. exit;
  48. }
  49. }

  1. public function MenuDel(){
  2. $mid = input('post.mid');
  3. if(empty($mid)){
  4. $arr = [
  5. 'code' => 1,
  6. 'msg' => '请传mid',
  7. ];
  8. echo json_encode($arr);
  9. exit;
  10. }
  11. $del = Db::table('yj_admin_menu')->where('mid',$mid)->delete();
  12. if(empty($del)){
  13. $arr = [
  14. 'code' => 1,
  15. 'msg' => '删除失败',
  16. ];
  17. echo json_encode($arr);
  18. exit;
  19. }else{
  20. $arr = [
  21. 'code' => 0,
  22. 'msg' => '删除成功',
  23. ];
  24. echo json_encode($arr);
  25. exit;
  26. }
  27. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post