The authorization class Authority. class. php is self-contained in the ThinkPHP framework. It's too much work to add all the operations to the permission table. only the operations to be verified can be added to the permission table. If the permission to be verified does not exist in the permission list (total list), this permission is granted by default (logged on ). Although the Code is easy to write, it is quite practical. ThinkPHP
The authorization class Authority. class. php is self-contained in the ThinkPHP framework. It's too much work to add all the operations to the permission table. only the operations to be verified can be added to the permission table. If the permission to be verified does not exist in the permission list (total list), this permission is granted by default (logged on ). Although the Code is easy to write, it is quite practical. ThinkPHP //
The authorization class Authority. class. php is self-contained in the ThinkPHP framework. It's too much work to add all the operations to the permission table.
Only the operations to be verified can be added to the permission table. If the permission to be verified does not exist in the permission list (total list), this permission is granted by default (logged on ).
Although the Code is easy to write, it is quite practical. ThinkPHP
// Get the permission $ name can be a string or an array or separated by commas. uid is the authenticated user ID, $ or is in the or relation, true is, and name is an array, if one of the conditions in the array is passed, it is passed. If it is false, all conditions must pass. // Last modification function: permission to be verified $ name if the permission list does not exist, this permission is granted by default to public function getAuth ($ name, $ uid, $ relation = 'or ') {if (! $ This-> _ config ['auth _ on']) return true; $ authList = $ this-> getAuthList ($ uid); if (is_string ($ name )) {if (strpos ($ name ,',')! = False) {$ name = explode (',', $ name);} else {$ name = array ($ name );}} // modify the part to start foreach ($ name as $ key => $ val) {if (! $ This-> isExistsRule ($ val) {unset ($ name [$ key]) ;}} if (count ($ name) == 0) {return true ;} // end of Modifying part $ list = array (); // name foreach ($ authList as $ val) with permission {if (in_array ($ val, $ name )) $ list [] = $ val;} if ($ relation = 'or' and! Empty ($ list) {return true;} $ diff = array_diff ($ name, $ list); if ($ relation = 'and' and empty ($ diff )) {return true;} return false;}/*** @ desc determines whether the database has the permission * @ param string $ name RuleName */public function isExistsRule ($ name) {static $ rule = array (); if (! Empty ($ rule [$ name]) {return $ rule [$ name];} $ rule [$ name] = M () -> table ($ this-> _ config ['auth _ rule'])-> where (array ('name' => $ name)-> count (); return $ rule [$ name];}