Role.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\user\controller;
  3. use app\base\controller\Base;
  4. use app\user\model\Rule;
  5. class Role extends Base{
  6. private $roleModel;
  7. public function _initialize(){
  8. parent::_initialize();
  9. $this->roleModel = new \app\user\model\Role();
  10. }
  11. public function index(){
  12. $p = $this->request->get('page', 0);
  13. $nick = $this->request->get('n');
  14. $where = [];
  15. if($nick) $where['nickname'] = ['like', "%$nick%"];
  16. $info = $this->roleModel->getInfo($p, $where);
  17. $page = $this->roleModel->getPage($where);
  18. $this->assign("info", $info);
  19. $this->assign("page", $page);
  20. return $this->fetch();
  21. }
  22. public function edit(){
  23. $id = $this->request->get('id');
  24. $info = $this->roleModel->getRoleById($id);
  25. $this->assign("info", $info);
  26. return $this->fetch();
  27. }
  28. public function set(){
  29. $id = $this->request->get('id');
  30. $rule = new Rule();
  31. $array = $rule->getInfo();
  32. $info = $rule->getRuleById($id);
  33. $role = $this->roleModel->getRoleById($id);
  34. $group = explode(",", $role['rules']);
  35. $this->assign("group", $group);
  36. $this->assign("array", $array);
  37. $this->assign("info", $info);
  38. return $this->fetch();
  39. }
  40. public function update(){
  41. $data = $this->request->post();
  42. $data['rules'] = implode(',', $data['rules']);
  43. $res = $this->roleModel->update($data);
  44. if($res){
  45. $this->success('保存成功!', 'index');
  46. }else{
  47. $this->error("保存失败!");
  48. }
  49. }
  50. public function save(){
  51. $res = $this->roleModel->addAndSave();
  52. if($res){
  53. $this->success('保存成功!', 'index');
  54. }else{
  55. $this->error('保存失败!');
  56. }
  57. }
  58. public function delete(){
  59. $res = $this->roleModel->remove();
  60. if($res){
  61. $this->success('删除成功!', 'index');
  62. }else{
  63. $this->error('删除失败!');
  64. }
  65. }
  66. }