Home> PHP Framework> ThinkPHP> body text

Module permission assignment in thinkphp

Release: 2020-05-23 09:06:25
forward
3075 people have browsed it

Module permission assignment in thinkphp

uses the Authority permission class that comes with ThinkPHP! ThinkPHP version is 3.1.3

What I want to achieve is to assign permissions based on the module name. Of course, this can be extended to the operation name.

If I have these module files:

Module permission assignment in thinkphp

Then the contents of the think_auth_rule table should be almost like this:

Module permission assignment in thinkphp

For example, my login user’s uid=7.

The think_auth_group_access table has uid=9, group=6;

The think_auth_group table has id=6, title=" Universe administrator", rules="4,5,8";

Then, I just need to add:

class CommAction extends Action{ public function __construct(){ parent::__construct(); $this->assign('waitSecond',2); $this->checkRight(); } private function checkRight(){ import('ORG.Util.Authority'); $auth=new Authority(); $r = $auth->getAuth(MODULE_NAME,session('S_USER_ID')); if(!$r){ $this->error('没有权限!'); } } }
Copy after login

to the module file CommAction.class.php, and then let other The module file inherits this file, for example, ActivityAction.class.php:

Copy after login

In this way, when I access the modules with IDs 4, 5, and 8 in think_auth_rules, I can access it normally;

If you access the module with ID 10, 11, 12, 13, it will jump to the page that fails and prompts that there is no permission~

Now the problem I encounter when using this permission class is: think_auth_rule table I need to add the content manually. This part is developed by attributes. It would be great if it could be automatically generated.

Recommended tutorial: "TP5"

The above is the detailed content of Module permission assignment in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:oschina.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!