PHP获取项目所有控制器方法名称

  //获取模块下所有的控制器和方法写入到权限表
public function initperm() {
$modules = array('admin'); //模块名称
$i = 0;
foreach ($modules as $module) {
$all_controller = $this->getController($module);
foreach ($all_controller as $controller) {
$all_action = $this->getAction($module, $controller);
foreach ($all_action as $action) {
$controller = str_replace('Controller', '', $controller);
$data[$i]['module'] = $module;
$data[$i]['controller'] = $controller;
$data[$i]['action'] = $action; //入库
if (!empty($module) && !empty($controller) && !empty($action)) {
$rule_name = $module . '-' . $controller . '-' . $action;
$rule = M()->table('tky_authrule')->where('name="' . strtolower($rule_name) . '"')->find();
if (!$rule) {
$idata = array();
$idata['module'] = strtolower($module . '-' . $controller);
$idata['type'] = "1";
$idata['name'] = strtolower($rule_name);
$idata['title'] = "";
$idata['regex'] = "";
$idata['status'] = "1";
M()->table('tky_authrule')->add($idata);
}
} $i++;
}
}
}
echo '<pre>';
print_r($data);
echo '</pre>';
} //获取所有控制器名称
private function getController($module) {
if (empty($module)) {
return null;
}
$module_path = APP_PATH . '/' . $module . '/controllers/'; //控制器路径
if (!is_dir($module_path)) {
return null;
}
$module_path .= '/*.php';
$ary_files = glob($module_path);
foreach ($ary_files as $file) {
if (is_dir($file)) {
continue;
} else {
$files[] = basename($file, '.php');
}
}
return $files;
} //获取所有方法名称
protected function getAction($module, $controller) {
if (empty($controller)) {
return null;
}
$file = APP_PATH . $module . '/controllers/' . $controller . '.php';
if (file_exists($file)) {
$content = file_get_contents($file);
preg_match_all("/.*?public.*?function(.*?)\(.*?\)/i", $content, $matches);
$functions = $matches[1];
//排除部分方法
$inherents_functions = array('_initialize', '__construct', 'getActionName', 'isAjax', 'display', 'show', 'fetch', 'buildHtml', 'assign', '__set', 'get', '__get', '__isset', '__call', 'error', 'success', 'ajaxReturn', 'redirect', '__destruct', '_empty');
foreach ($functions as $func) {
$func = trim($func);
if (!in_array($func, $inherents_functions)) {
$customer_functions[] = $func;
}
}
return $customer_functions;
} else {
\ticky\Log::record('is not file ' . $file, Log::INFO);
}
return null;
}

 mysql

DROP TABLE IF EXISTS tky_authrule;
CREATE TABLE tky_authrule (
ruleid MEDIUMINT (8) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号',
module VARCHAR (20) NOT NULL DEFAULT '' COMMENT '规则所属module',
type TINYINT (1) NOT NULL DEFAULT '1' COMMENT '类型 1-url;2-主菜单',
name CHAR (80) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识',
title CHAR (20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
regex CHAR (100) NOT NULL DEFAULT '' COMMENT '规则表达式',
status TINYINT (1) NOT NULL DEFAULT '1' COMMENT '状态',
PRIMARY KEY (ruleid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT = '规则表';

  

PHP获取项目所有控制器方法名称的更多相关文章

  1. java获取当前运行的方法名称

    // 这种方式获取的话,数组的第一个元素是当前运行方法的名称,第二个元素是调用当前方法的方法名称 StackTraceElement[] stackTrace = new Exception().ge ...

  2. javaweb获取项目路径的方法

    在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getPro ...

  3. js获取项目根目录的方法

    getRootPath = function(){ //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp var curWwwPat ...

  4. C#应用程序获取项目路径的方法总结

    一.非Web程序   //基目录,由程序集冲突解决程序用来探测程序集 1.AppDomain.CurrentDomain.BaseDirectory     //当前工作目录的完全限定路径2.Envi ...

  5. 获取DLL中的方法名称

      OpenFileDialog obj = new OpenFileDialog(); if (obj.ShowDialog() == System.Windows.Forms.DialogResu ...

  6. jsp中的js中获取项目路径的方法

    在jsp中加上 <% String path = request.getContextPath(); String basePath = request.getScheme()+":/ ...

  7. Java中动态获取项目根目录的绝对路径

    https://www.cnblogs.com/zhouqing/archive/2012/11/10/2757774.html 序言 在开发过程中经常会用到读写文件,其中就必然涉及路径问题.使用固定 ...

  8. legend3---laravel中获取控制器名称和方法名称

    legend3---laravel中获取控制器名称和方法名称 一.总结 一句话总结: \Route::current()->getActionName();会有完整的当前控制器名和方法名 pub ...

  9. Codeigniter 获取当前的控制器名称和方法名称

    在Codeigniter 可以通过下面两个方法获取当前的控制器名称和方法名称 $this->router->fetch_class(); $this->router->fetc ...

随机推荐

  1. [转]layui点击左侧导航栏,实现不刷新整个页面,只刷新局部

    本文转自:https://blog.csdn.net/s31415926_004/article/details/84256587 其实这篇文章是给自己看的,以后忘记怎么做回来还能看一下哈哈哈哈哈哈哈 ...

  2. 杭电ACM2013--蟠桃记

    蟠桃记 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  3. win10下rdlc报表在vs(visual studio)中中文显示小方块的批量处理解决方法

    在网上找vs中rdlc报表显示中文时显示小方块的解决方案,无外就是修改文本框的字体属性.但是对于维护已有的rdlc报表时,有中文的地方(此时都显示了小方块)会很多,再一个一个设置实在太麻烦.所以自己花 ...

  4. Android开发——EditText的属性使用

    最近使用的EditText控件,有些属性不太清楚,做一下笔记   判断EditText中内容是否为空 EditText多行显示 android:inputType="textMultiLin ...

  5. Html和Css学习笔记-css基础知识

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 此篇博客是我的复习笔记,html和css学的时间太久了,忘得差不多了,最近要使用一下,所以重新打开html的书略读,后记录了标签 ...

  6. 作为JavaScript开发人员,这些必备的VS Code插件你都用过吗?

    本文翻译自:https://www.sitepoint.com/vs-code-extensions-javascript-developers/ 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的 ...

  7. 当view为wrap_conten时获取一个view的具体宽高

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec. ...

  8. MySQL5.5.51启用网络远程连接

    在其它电脑主机上访问时提示host ip is not allowed to connect to this mysql 下面代码为解决该问题的方法: :\Program Files\mysql-\b ...

  9. iOS中图片拉伸,类似Android中的点9图片

    UIImage* img=[UIImage imageNamed:@"name.png"];//原图 UIEdgeInsets edge=UIEdgeInsetsMake(, , ...

  10. Cs231n课堂内容记录-Lecture 5 卷积神经网络介绍

    Lecture 5 CNN 课堂笔记参见:https://zhuanlan.zhihu.com/p/22038289?refer=intelligentunit 不错的总结笔记:https://blo ...