Authority. class. php modify the permission to be verified $ name if the permission list is not

Source: Internet
Author: User
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];}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.