大家覺得此處為啥要清空原權(quán)限呢?
//配置權(quán)限處理難點
public function accessPost()
{
$rid = I('rid', 0, 'intval');
$access = array();
//組合權(quán)限
foreach (I('access', array()) as $v) {
$tmp = explode('_', $v);
$access[] = array('role_id' => $rid, 'node_id' => $tmp[0], 'level' => $tmp[1]);
}
//清空原權(quán)限
M('access')->where(array('role_id' => $rid))->delete();
if (empty($access)) {
$this->success('配置成功', U('Rbac/role'));
}
//插入新權(quán)限
//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('配置失敗');
}
}