public function access() { $this->web_title = '分配权限'; if (IS_POST) { $roleId = I('role_id', 0, 'intval'); $data = array(); foreach (I('node_id') as $val) { $tmp = explode('_', $val); $data[] = array('role_id' => $roleId, 'node_id' => $tmp[0], 'level' => $tmp[1]); } M('access')->where(array('role_id' => $roleId))->delete(); if (M('access')->addAll($data)) { $this->success('保存成功', U(MODULE_NAME . '/Rbac/access', array('id' => $roleId))); } else { $this->error('保存失败'); } return; } $id = I('id'); if ($id) { $this->role_id = $id; } else { $this->redirect(MODULE_NAME . '/Rbac/role'); } $nodes = M('node')->order('sort')->select(); $access = M('access')->where(array('role_id' => $id))->getField('node_id', true); $this->nodes = Category::prepareForAccess($nodes, 0, $access); $this->display(); }