MenuController.class.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Think\Controller;
  16. class MenuController extends CommonController {
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='系统';
  20. $this->breadcrumb2='后台菜单配置';
  21. }
  22. function index(){
  23. $cate = M()->query('SELECT id,pid,title AS name FROM '.C('DB_PREFIX').'menu ORDER BY sort_order ASC');
  24. $list =list_to_tree($cate);
  25. $this->list=json_encode($list);
  26. $this->display();
  27. }
  28. function add(){
  29. if(IS_POST){
  30. $d['title']=I('title');
  31. $d['url']=I('url');
  32. $d['sort_order']=I('sort_order');
  33. $d['pid']=I('id');
  34. $id=M('Menu')->add($d);
  35. if($id){
  36. $data['name'] =$d['title'];
  37. $data['id']=$id;
  38. $this->ajaxReturn($data);
  39. die();
  40. }else{
  41. die();
  42. }
  43. }
  44. }
  45. function edit(){
  46. if(IS_POST){
  47. $d['id']=I('id');
  48. $d['title']=I('title');
  49. $d['url']=I('url');
  50. $d['sort_order']=I('sort_order');
  51. $r=M('Menu')->save($d);
  52. if($r){
  53. $data['success']='修改成功';
  54. $data['name']=$d['title'];
  55. $this->ajaxReturn($data);
  56. die();
  57. }else{
  58. $data['err']='修改失败';
  59. $this->ajaxReturn($data);
  60. die();
  61. }
  62. }
  63. }
  64. function del(){
  65. if(IS_POST){
  66. $id=I('id');
  67. if(M('Menu')->where('id='.$id)->delete()){
  68. $this->ajaxReturn('删除成功');
  69. die();
  70. }
  71. }
  72. }
  73. function get_info(){
  74. if(IS_POST){
  75. $id=I('id');
  76. $d=M('Menu')->find($id);
  77. $data['title']=$d['title'];
  78. $data['url']=$d['url'];
  79. $data['sort_order']=$d['sort_order'];
  80. $this->ajaxReturn($data);
  81. }
  82. }
  83. }