Provides various official and user-released code examples. For code reference, you are welcome to learn ThinkPHP 3.2.2 to get the name of all the methods of the project. Purpose: Haha!
If you use a multi-level controller, modify the code on your own.
Public function index (){
$ Modules = array ('admin'); // Module name
$ I = 0;
Foreach ($ modules as $ module ){
$ All_controller = $ this-> getController ($ module );
Foreach ($ all_controller as $ controller ){
$ Controller_name = $ module. '/'. $ controller;
$ All_action = $ this-> getAction ($ controller_name );
Foreach ($ all_action as $ action ){
$ Data [$ I] ['module'] = $ module;
$ Data [$ I] ['controller'] = $ controller;
$ Data [$ I] ['action'] = $ action;
$ I ++;
}
}
}
Echo'
';
Print_r ($ data );
}
// Obtain the names of all controllers
Protected function getController ($ module ){
If (empty ($ module) return null;
$ Module_path = APP_PATH. '/'. $ module. '/Controller/'; // Controller path
If (! Is_dir ($ module_path) return null;
$ Module_path. = '/*. class. php ';
$ Ary_files = glob ($ module_path );
Foreach ($ ary_files as $ file ){
If (is_dir ($ file )){
Continue;
} Else {
$ Files [] = basename ($ file, C ('default _ C_LAYER ').'. class. php ');
}
}
Return $ files;
}
// Obtain the names of all methods
Protected function getAction ($ controller ){
If (empty ($ controller) return null;
$ Con = A ($ controller );
$ Functions = get_class_methods ($ con );
// Exclude some methods
$ 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 ){
If (! In_array ($ func, $ inherents_functions )){
$ Customer_functions [] = $ func;
}
}
Return $ customer_functions;
}Changed to get all public methods using regular expressions.Public function index (){
$ Modules = array ('admin'); // Module name
$ I = 0;
Foreach ($ modules as $ module ){
$ All_controller = $ this-> getController ($ module );
Foreach ($ all_controller as $ controller ){
$ Controller_name = $ controller;
$ All_action = $ this-> getAction ($ module, $ controller_name );
Foreach ($ all_action as $ action ){
$ Data [$ I] = array (
'Name' => $ controller. '_'. $ action,
'Status' => 1
);
$ I ++;
}
}
}
Echo'';
Print_r ($ data );
}
// Obtain the names of all controllers
Protected function getController ($ module ){
If (empty ($ module) return null;
$ Module_path = APP_PATH. '/'. $ module. '/Controller/'; // Controller path
If (! Is_dir ($ module_path) return null;
$ Module_path. = '/*. class. php ';
$ Ary_files = glob ($ module_path );
Foreach ($ ary_files as $ file ){
If (is_dir ($ file )){
Continue;
} Else {
$ Files [] = basename ($ file, C ('default _ C_LAYER ').'. class. php ');
}
}
Return $ files;
}
// Obtain the names of all methods
Protected function getAction ($ module, $ controller ){
If (empty ($ controller) return null;
$ Content = file_get_contents (APP_PATH. '/'. $ module. '/Controller/'. $ controller. 'controller. class. php ');
Preg_match_all ("/.*? Public .*? Function (.*?) \(.*? \)/I ", $ content, $ matches );
$ Functions = $ matches [1];
// Exclude some methods
$ 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;
}AD: truly free, domain name + VM + enterprise mailbox = 0 RMB