我的思路是:

  1. 读取控制器文件夹下的所有 php 文件
  2. 获取父级的控制器的方法的不应该出现在每个控制器的路由中,所以需要排除父级控制器的方法
  3. 读取 控制器文件夹下的 php文件的类名和方法

下面的代碼是在控制器中的1個方法

 public function test(){
$controller_path = APPPATH . 'controllers/';
$controller_files = glob($controller_path.'*.php'); $ignore_controller_file_names = array(
'Welcome.php'
); if(count($ignore_controller_file_names) > 0){
foreach ($ignore_controller_file_names as $file_name){
$test_controller_file = array_search($controller_path.$file_name, $controller_files);
if($test_controller_file !== false){
unset($controller_files[$test_controller_file]);
}
}
} //router need ignore method form extend controller
$controller_parent_files = array(
array(
'file_path' => BASEPATH.'core/Controller.php',
'class_name' => 'CI_Controller',
),
//if have create MY_Controller.php in application/core folder
array(
'file_path' => APPPATH.'core/MY_Controller.php',
'class_name' => 'MY_Controller', ),
);
$ignore_methods = array();
if(count($controller_parent_files) > 0){
foreach ($controller_parent_files as $controller_parent_file){
include_once $controller_parent_file['file_path'];
$controller_methods = get_class_methods($controller_parent_file['class_name']);
foreach ($controller_methods as $method){
if(!in_array($method,$ignore_methods)){
$ignore_methods[] = $method;
}
}
}
} // $ignore_methods = array(
// //ignore CI_Controller get_instance method()
// '__construct',
// 'get_instance',
// //ignore MY_Controller's public/protected methods
// ); $echo_router = true;
$routers = array();
foreach ($controller_files as $controller_file){
include_once $controller_file;
$tmp_file_name = str_replace($controller_path,'',$controller_file);
$controller_name = lcfirst(str_replace('.php','',$tmp_file_name)); $class_methods = get_class_methods($controller_name);
foreach ($class_methods as $key=>$class_method){
if(in_array($class_method,$ignore_methods)){
unset($class_methods[$key]);
continue;
}
if($echo_router){
echo "{$controller_name}/{$class_method}<br/>";
} }
$routers[$controller_name] = array(
'class_name' => ucfirst($controller_name),
'class' => $controller_name,
'methods' => $class_methods
);
} ksort($routers); // echo "<pre>";
// print_r($routers);
// echo "</pre>";
}
References
  1. how to get all list of controllers and methods without MY_controller and Ci_controller methods in codeigniter?

Codeigniter 列出所有控制器和控制器的方法(类似路由列表)的更多相关文章

  1. springmvc2 一个控制器写多个方法(非注解方式)

    出处:http://blog.csdn.net/xuewenke/article/details/23895999 springmvc2 一个控制器写多个方法(非注解方式) 分类: spring 20 ...

  2. iOS开发——UI进阶篇(八)pickerView简单使用,通过storyboard加载控制器,注册界面,通过xib创建控制器,控制器的view创建,导航控制器的基本使用

    一.pickerView简单使用 1.UIPickerViewDataSource 这两个方法必须实现 // 返回有多少列 - (NSInteger)numberOfComponentsInPicke ...

  3. iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期

    iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期 一.基本过程 新建一个项目,系统默认的主控制器继承自UIViewController,把主控制器两个文件删掉. 在stor ...

  4. laravel6.0控制器-资源控制器

    控制器:控制器用来处理业务的,不应该处理逻辑,如果是小项目可以把逻辑写到控制器里,大点的项目应该抽离出来业务处理层如下:services业务处理层:比如:获取值,验证值,异常捕获命名规则:控制器名:用 ...

  5. Jmeter(七)_if控制器+循环控制器+计数器控制接口分支

    最近查阅了一下网上关于if控制器的文章,大同小异,几乎找不到原创,于是决定自己写一篇 下午测试接口,遇到了一个审核的流程.逻辑很简单,就是审核不通过之后返回去继续修改再提交,然后再审核,直到通过为止. ...

  6. iOS:使用block进行类与类,控制器与控制器之间的传值

    介绍:在iOS中类与类,控制器与控制器之间传值的方式有多种,分别是:单例传值.代理传值.通知传值.block传值或者一些偏好设置也可以用来传值.... 每一种传值方式都有各自的优点和缺点,针对不同情况 ...

  7. 建立tracert路由列表的方法

    建立tracert路由列表的方法:电脑屏幕左下方 选择开始选项运行 输入 CMD在DOS命令行下输入:tracert (你的网站域名)   运行结果中如出现了“*     *     *    req ...

  8. 兰亭集势笔试题:用最优方法从LinkedList列表中删除重复元素

    用运行速度最优的方法从LinkedList列表里删除重复的元素,例如A->B->BB->B->C,返回A->B->BB->C. 考试的时候没完全想明白,考完又 ...

  9. python练习题,写一个方法 传进去列表和预期的value 求出所有变量得取值可能性(例如list为[1,2,3,4,5,6,12,19],value为20,结果是19+1==20只有一种可能性),要求时间复杂度为O(n)

    题目:(来自光荣之路老师)a+b==valuea+b+c=valuea+b+c+d==valuea+b+c+d+...=valuea和b....取值范围都在0-value写一个方法 传进去列表和预期得 ...

随机推荐

  1. Linux面试基础(一)

    Linux基本命令 man rm   查看命令帮助 tar cf 压缩文件 tar xf 解压缩 ping  查看是否能连接网络 rm           删除数据 find          搜索数 ...

  2. JavaWeb开发之二《JSP + Tomcat的第一个程序“Hello World”》

    搬以前写的博客[2014-12-10 22:41] 前一篇博客讲了Tomcat环境搭建,于是开始第一个“Hello JSP”程序. 服务器环境搭建好之后,我们开始写自己的网站,这里简单的写一个没有后台 ...

  3. React defaultProps

    defaultProps // 为属性指定默认值:Greeting.defaultProps = { name: 'Stranger'}; defaultProps 用来确保 this.props.n ...

  4. vue X-Template

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. 超实用的HTML代码段(赵荣娇)

    第1章 创建HTML文档 11.1 HTML文档的基本结构 2 <html> <head> <title>Title of page</title> & ...

  6. Oracle系列教程之一软件安装与卸载

    1.安装软件 软件下载地址:https://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html ...

  7. 深入理解Magento - 第六章 - 高级Magento模型

    我们讲过Magento有两种模型,简单模型和EAV(Entity Attribute Value)模型.上一章我们讲过所有的Magento模型都是继承自Mage_Core_Model_Abstract ...

  8. SQL 与,或,非

    SQL AND, OR and NOT(与,或不是运算符) AND&OR运算符用于根据一个以上的条件过滤记录. SQL AND & OR 运算符 WHERE子句可以与AND,OR和NO ...

  9. Work 4(通知类) (2019.04.25)

  10. 对Map的key按升序进行排序

    //对Map的key按升序进行排序 List<Map.Entry<Integer,Task>> mappingList = new ArrayList<Map.Entry ...