search
Homephp教程php手册自动获取所有模块的函数,用于RBAC节点和菜单数据

系统开发好以后,你知道系统里有多少个Module不?知道有多少个Action不?

你的RBAC是不是需要用这些数据?你的菜单是不是需要用这些数据?

亲,厌倦了手动录入吗?你找我算是对人了。

代码来源:开源ThinkPHP代码生成器
应用主页:http://rockefys.github.io/commlib//生成模块结构信息 app/分组/模块/方法<br>     public function fetch_module(){<br>         $M = M('Module');<br>         $M->query("truncate table module");<br>         $app = $this->getAppName();<br>         $groups = $this->getGroup();<br>         $n=0;<br>         foreach ($groups as $group) {<br>             $modules = $this->getModule($group);<br>             foreach ($modules as $module) {<br>                 $module_name=$app.'://'.$group.'/'.$module;<br>                 $functions = $this->getFunction($module_name);<br>                 foreach ($functions as $function) {<br>                     $data[$n]['app'] = $app;<br>                     $data[$n]['group'] = $group;<br>                     $data[$n]['module'] = $module;<br>                     $data[$n]['function'] = $function;<br>                     ++$n;                                }<br>             }<br>         }<br>         $M->addAll($data);<br>         $this->success('所有分组/模块/方法已成功读取到module表中.');<br>     }<br>     protected function getAppName(){<br>         return APP_NAME;<br>     }<br> <br>     protected function getGroup(){<br>         $result = explode(',',C('APP_GROUP_LIST'));<br>         return $result;<br>     }<br> <br>     protected function getModule($group){<br>         if(empty($group))return null;<br>         $group_path=LIB_PATH.'Action/'.$group;<br>         if(!is_dir($group_path))return null;<br>         $group_path.='/*.class.php';<br>         $ary_files = glob($group_path);<br>         foreach ($ary_files as $file) {<br>             if (is_dir($file)) {<br>                 continue;<br>             }else {<br>                     $files[] = basename($file,'Action.class.php');<br>             }<br>         }<br>         return $files;<br> <br>     }<br> <br>     protected function getFunction($module){<br>         if(empty($module))return null;<br>         $action=A($module);<br>         $functions=get_class_methods($action);<br>         $inherents_functions = array(<br>             '_initialize','__construct','getActionName','isAjax','display','show','fetch',<br>             'buildHtml','assign','__set','get','__get','__isset',<br>             '__call','error','success','ajaxReturn','redirect','__destruct'<br>         );<br> <br>         foreach ($functions as $func){<br>             if(!in_array($func, $inherents_functions)){<br>                 $customer_functions[]=$func;<br>             }<br>         }<br>         return $customer_functions;<br>     }module表结构CREATE TABLE `module` (<br>   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br>   `name` varchar(45) DEFAULT NULL COMMENT '名称',<br>   `app` varchar(45) DEFAULT NULL COMMENT '项目',<br>   `group` varchar(45) DEFAULT NULL COMMENT '分组',<br>   `module` varchar(45) DEFAULT NULL COMMENT '模块',<br>   `function` varchar(45) DEFAULT NULL COMMENT '方法',<br>   `status` varchar(45) DEFAULT NULL COMMENT '状态',<br>   PRIMARY KEY (`id`)<br> ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$思路讲解:很简单,
1、根据配置文件获取分组
2、遍历分组下的Action文件夹中的*Action.class.php
3、实例化Action,获取其所有方法,过滤掉tp本身的底层函数,
4、小手一挥,数据到手.
getFunction代码讲解:$action=A($module);<br> $functions=get_class_methods($action);//获取该类的所有方法<br> $inherents_functions = array(...);//tp自带的底层函数

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)