| 基于ext系统的rbac设计 |
| 2008-07-06 | |
|
最近在开发GM系统,由于e使用ext变得限制很多,设计一套rbac系统,支持多子系统,多角色,今天实现解决方案,给出数据库设计及实例代码,希望大家有所帮助。
<?php function getPermissionName($id,$db){ $sql = 'select * from pemissions where permission_id='.$id; $rs = $db->query($sql); while ($row = $rs->fetch_assoc()) { $arr['id'] = $row['permission_id']; $arr['text'] = $row['permission_chinese_name']; } return $arr; } $db = new mysqli('localhost','root','','gboss'); $db->set_charset('UTF8'); $sql2 = 'select distinct(child_sys_id) from child_sys_has_permissions where roles_id in(select roles_id from user_has_roles where user_id=3)'; $rs2 = $db->query($sql2); while ($row2 = $rs2->fetch_assoc()) { $sys[] = $row2['child_sys_id']; } /////////////////////////////// foreach ($sys as $val) { $sql = 'select child_sys_id,permission_id,parent_id from child_sys_has_permissions where child_sys_id='.$val.' and roles_id in(select roles_id from user_has_roles where user_id=1)'; $rs = $db->query($sql); while ($row = $rs->fetch_assoc()) { if ($row['parent_id']==0) { $temp['root'][] = getPermissionName($row['permission_id'],$db); } else { $temp[$row['parent_id']][] = getPermissionName($row['permission_id'],$db); } } $all[$val] = $temp; unset($temp); } var_export($all);//这里返回所具备的权限,格式化成json数据,即可生成权限树 ?> 数据库er图下载:http://www.extshow.com/download/er.vsd |
| < 上一篇 | 下一篇 > |
|---|