大家觉得此处为啥要清空原权限呢?
//配置权限处理难点
public function accessPost()
{
$rid = I('rid', 0, 'intval');
$access = array();
//组合权限
foreach (I('access', array()) as $v) {
$tmp = explode('_', $v);
$access[] = array('role_id' => $rid, 'node_id' => $tmp[0], 'level' => $tmp[1]);
}
//清空原权限
M('access')->where(array('role_id' => $rid))->delete();
if (empty($access)) {
$this->success('配置成功', U('Rbac/role'));
}
//插入新权限
//mysql,支持addAll
$ret = 0;
if (in_array(strtolower(C('DB_TYPE')), array('mysql', 'mysqli', 'mongo'))) {
$ret = M('access')->addAll($access);
} else {
foreach ($access as $v) {
$ret = M('access')->add($v);
}
}
if ($ret) {
$this->success('配置成功', U('Rbac/role'));
} else {
$this->error('配置失败');
}
}