ThinkPHP 3.2.2 获取项目所有方法名称,用途:呵呵!
如果使用了多级控制器,请自行修改代码。 public function index(){<br>
$modules = array('Admin'); //模块名称<br>
$i = 0;<br>
foreach ($modules as $module) {<br>
$all_controller = $this->getController($module);<br>
foreach ($all_controller as $controller) {<br>
$controller_name = $module.'/'.$controller;<br>
$all_action = $this->getAction($controller_name);<br>
foreach ($all_action as $action) {<br>
$data[$i]['module'] = $module;<br>
$data[$i]['controller'] = $controller;<br>
$data[$i]['action'] = $action;<br>
$i++;<br>
}<br>
}<br>
}<br>
echo '<pre class="brush:php;toolbar:false">';<br>
print_r($data);<br>
}<br>
//获取所有控制器名称<br>
protected function getController($module){<br>
if(empty($module)) return null;<br>
$module_path = APP_PATH . '/' . $module . '/Controller/'; //控制器路径<br>
if(!is_dir($module_path)) return null;<br>
$module_path .= '/*.class.php';<br>
$ary_files = glob($module_path);<br>
foreach ($ary_files as $file) {<br>
if (is_dir($file)) {<br>
continue;<br>
}else {<br>
$files[] = basename($file, C('DEFAULT_C_LAYER').'.class.php');<br>
}<br>
}<br>
return $files;<br>
}<br>
//获取所有方法名称<br>
protected function getAction($controller){<br>
if(empty($controller)) return null;<br>
$con = A($controller);<br>
$functions = get_class_methods($con);<br>
//排除部分方法<br>
$inherents_functions = array('_initialize','__construct','getActionName','isAjax','display','show','fetch','buildHtml','assign','__set','get','__get','__isset','__call','error','success','ajaxReturn','redirect','__destruct', '_empty');<br>
foreach ($functions as $func){<br>
if(!in_array($func, $inherents_functions)){<br>
$customer_functions[] = $func;<br>
}<br>
}<br>
return $customer_functions;<br>
}</pre>
改了下,用正则获取所有公共方法 public function index(){<br>
$modules = array('Admin'); //模块名称<br>
$i = 0;<br>
foreach ($modules as $module) {<br>
$all_controller = $this->getController($module);<br>
foreach ($all_controller as $controller) {<br>
$controller_name = $controller;<br>
$all_action = $this->getAction($module, $controller_name);<br>
foreach ($all_action as $action) {<br>
$data[$i] = array(<br>
'name' => $controller . '_' . $action,<br>
'status' => 1<br>
);<br>
$i++;<br>
}<br>
}<br>
}<br>
echo '<pre class="brush:php;toolbar:false">';<br>
print_r($data);<br>
}<br>
<br>
//获取所有控制器名称<br>
protected function getController($module){<br>
if(empty($module)) return null;<br>
$module_path = APP_PATH . '/' . $module . '/Controller/'; //控制器路径<br>
if(!is_dir($module_path)) return null;<br>
$module_path .= '/*.class.php';<br>
$ary_files = glob($module_path);<br>
foreach ($ary_files as $file) {<br>
if (is_dir($file)) {<br>
continue;<br>
}else {<br>
$files[] = basename($file, C('DEFAULT_C_LAYER').'.class.php');<br>
}<br>
}<br>
return $files;<br>
}<br>
<br>
//获取所有方法名称<br>
protected function getAction($module, $controller){<br>
if(empty($controller)) return null;<br>
$content = file_get_contents(APP_PATH . '/'.$module.'/Controller/'.$controller.'Controller.class.php');<br>
preg_match_all("/.*?public.*?function(.*?)\(.*?\)/i", $content, $matches);<br>
$functions = $matches[1];<br>
//排除部分方法<br>
$inherents_functions = array('_initialize','__construct','getActionName','isAjax','display','show','fetch','buildHtml','assign','__set','get','__get','__isset','__call','error','success','ajaxReturn','redirect','__destruct','_empty');<br>
foreach ($functions as $func){<br>
$func = trim($func);<br>
if(!in_array($func, $inherents_functions)){<br>
$customer_functions[] = $func;<br>
}<br>
}<br>
return $customer_functions;<br>
}</pre>
AD:真正免费,域名+虚机+企业邮箱=0元