无限星辰工作室-客户无限互联网动力之源

标题: thinkphp 3.2.3获取当前项目下所有的控制器方法名称 [打印本页]

作者: crx349    时间: 2018-8-15 15:20
标题: thinkphp 3.2.3获取当前项目下所有的控制器方法名称
  1. //获取所有控制器名称
  2. protected function getController($module){
  3. if(empty($module)) return null;
  4. $module_path = APP_PATH . '/' . $module . '/Controller/'; //控制器路径
  5. if(!is_dir($module_path)) return null;
  6. $module_path .= '/*.class.php';
  7. $ary_files = glob($module_path);
  8. foreach ($ary_files as $file) {
  9. if (is_dir($file)) {
  10. continue;
  11. }else {
  12. $files[] = basename($file, C('DEFAULT_C_LAYER').'.class.php');
  13. }
  14. }
  15. $i = array('Com','Qq','Shop','Payment','abc');
  16. foreach ($files as $func){
  17. if(!in_array($func, $i)){
  18. $arrr[] = $func;
  19. }
  20. }
  21. return $arrr;
  22. }
  23. //获取所有方法名称
  24. protected function getAction($controller){
  25. if(empty($controller)) return null;
  26. $con = A($controller);
  27. $functions = get_class_methods($con);
  28. //排除部分方法
  29. $inherents_functions = array(
  30. '_initialize','__construct','getActionName',
  31. 'isAjax','display','show','fetch','buildHtml','assign','__set','get',
  32. '__get','__isset','__call','error','success','ajaxReturn','redirect',
  33. '__destruct', '_empty','verify','validateUser','createSn','getpage',
  34. 'json','xml','xmlTo','theme'
  35. );
  36. foreach ($functions as $func){
  37. if(!in_array($func, $inherents_functions)){
  38. $customer_functions[] = $func;
  39. }
  40. }
  41. return $customer_functions;
  42. }


  43. //获取所有控制器下的所有方法
  44. public function abc(){


  45. $a = $this->getController('Shequapp');
  46. for ($i=0; $i <count($a) ; $i++) {
  47. $c[$a[$i]]= $this->getAction($a[$i]);
  48. }

  49. p($c);
  50. }
复制代码





欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4