首页 > php教程 > php手册 > 正文

自动获取所有模块的函数,用于RBAC节点和菜单数据

php中文网
发布: 2016-06-07 11:44:44
原创
1353人浏览过

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

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

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

代码来源:开源ThinkPHP代码生成器
应用主页:http://rockefys.github.io/commlib//生成模块结构信息 app/分组/模块/方法<br>     public function fetch_module(){<br>         $M = M('Module');<br>         $M-&gt;query("truncate table module");<br>         $app = $this-&gt;getAppName();<br>         $groups = $this-&gt;getGroup();<br>         $n=0;<br>         foreach ($groups as $group) {<br>             $modules = $this-&gt;getModule($group);<br>             foreach ($modules as $module) {<br>                 $module_name=$app.'://'.$group.'/'.$module;<br>                 $functions = $this-&gt;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-&gt;addAll($data);<br>         $this-&gt;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元

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号