ThinkPHP3.2.2 get the name of all the methods of the project

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.