1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\user\controller;
- use app\base\controller\Base;
- use app\user\model\Rule;
- class Role extends Base{
-
- private $roleModel;
-
- public function _initialize(){
- parent::_initialize();
-
- $this->roleModel = new \app\user\model\Role();
- }
-
- public function index(){
- $p = $this->request->get('page', 0);
- $nick = $this->request->get('n');
- $where = [];
-
- if($nick) $where['nickname'] = ['like', "%$nick%"];
-
- $info = $this->roleModel->getInfo($p, $where);
- $page = $this->roleModel->getPage($where);
-
- $this->assign("info", $info);
- $this->assign("page", $page);
- return $this->fetch();
- }
-
- public function edit(){
- $id = $this->request->get('id');
- $info = $this->roleModel->getRoleById($id);
-
- $this->assign("info", $info);
- return $this->fetch();
- }
-
- public function set(){
- $id = $this->request->get('id');
- $rule = new Rule();
- $array = $rule->getInfo();
- $info = $rule->getRuleById($id);
- $role = $this->roleModel->getRoleById($id);
- $group = explode(",", $role['rules']);
-
- $this->assign("group", $group);
- $this->assign("array", $array);
- $this->assign("info", $info);
- return $this->fetch();
- }
-
- public function update(){
- $data = $this->request->post();
- $data['rules'] = implode(',', $data['rules']);
- $res = $this->roleModel->update($data);
-
- if($res){
- $this->success('保存成功!', 'index');
- }else{
- $this->error("保存失败!");
- }
- }
-
- public function save(){
- $res = $this->roleModel->addAndSave();
-
- if($res){
- $this->success('保存成功!', 'index');
- }else{
- $this->error('保存失败!');
- }
- }
-
- public function delete(){
- $res = $this->roleModel->remove();
-
- if($res){
- $this->success('删除成功!', 'index');
- }else{
- $this->error('删除失败!');
- }
- }
-
- }
|