RBAC (Role-BasedAccessControl, Role-based access control) means that users are associated with permissions through roles. Simply put, a user has several roles and each role has several permissions. In this way, the authorization model of "user-role-permission" is constructed. In this model, the relationship between users and roles and between roles and permissions is usually many-to-many.
Before talking about permission management, we should first know what functions permission management should have:
(1) users can only access the specified controller and method.
(2) users can exist in multiple user groups.
(3) users can select the specified controller and method.
(4) you can add controllers and methods.
Role-Based Access Control (RBAC) is used to associate users with permissions through roles. Simply put, a user has several roles and each role has several permissions. In this way, the authorization model of "user-role-permission" is constructed. In this model, the relationship between users and roles and between roles and permissions is usually many-to-many.
2. administrator management page,
Query($sql); foreach ($arr as $v) { echo "{$v[2]}"; } ?>
(1). display the user name and role name respectively.
(2). change the role in the check box according to the change in the drop-down user name.
(3) When modifying a user role, you must first delete all user information in the table corresponding to the user role, and then add the obtained user name and role code.
Use the drop-down list: embedded php query and Traverse. the following drop-down list is displayed:
Select a role. use the multiple choice box:
Select a role
$ Sjs = "select * from qxzw ";
$ Ajs = $ db-> Query ($ sjs );
Foreach ($ ajs as $ v ){
Echo"{$ V [1]} ";
}?>
Figure:
When a user changes, the corresponding role also changes, and the role information of the person is changed, added and saved, the basic idea of adding and saving is to first delete all the role information corresponding to the personnel in the database, then retrieve the selected part and add it to the database.
First, let him select the default role:
Script // select the default role function xuan () {var uid = $ ("# user "). val (); $. ajax ({url: "chuli. php ", data: {uid: uid, type: 0}, type:" POST ", dataType:" TEXT ", success: function (data) {var juese = data. trim (). split ("|"); // The Code var ck = $ (". ck "); ck. prop ("checked", false); for (var I = 0; I
= 0) {ck. eq (I). prop ("checked", true) ;}}});} script
To write his processing page:
strQuery($sql);break;}
Check the final result. after successful logon, the homepage is displayed. if logon fails, an error is returned.
Then, click the save button:
Script // select the corresponding role $ ("# user") when the user changes "). change (function () {xuan () ;}) // Click OK to save the role information $ ("# btn "). click (function () {var uid = $ ("# user "). val (); // find the username var juese = ""; // find the role code var ck = $ (". ck "); // find all checked for (var I = 0; I
Processing page:
Query ($ sdel, 0); // string obtained by splitting $ arr = explode ("|", $ juese); foreach ($ arr as $ v) {$ SQL = "insert into qxyhzw VALUES ('', '{$ uid}', '{$ v}') "; $ db-> query ($ SQL, 0);} echo "OK"; break ;}
View results:
Total management page code:
Untitled Document