suchen
Heimphp教程php手册ThinkPHP 3.2.2 获取项目所有方法名称

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">';&lt;br&gt;         print_r($data);&lt;br&gt;     }&lt;br&gt;     //获取所有控制器名称&lt;br&gt;     protected function getController($module){&lt;br&gt;         if(empty($module)) return null;&lt;br&gt;         $module_path = APP_PATH . '/' . $module . '/Controller/';  //控制器路径&lt;br&gt;         if(!is_dir($module_path)) return null;&lt;br&gt;         $module_path .= '/*.class.php';&lt;br&gt;         $ary_files = glob($module_path);&lt;br&gt;         foreach ($ary_files as $file) {&lt;br&gt;             if (is_dir($file)) {&lt;br&gt;                 continue;&lt;br&gt;             }else {&lt;br&gt;                 $files[] = basename($file, C('DEFAULT_C_LAYER').'.class.php');&lt;br&gt;             }&lt;br&gt;         }&lt;br&gt;         return $files;&lt;br&gt;     }&lt;br&gt;     //获取所有方法名称&lt;br&gt;     protected function getAction($controller){&lt;br&gt;         if(empty($controller)) return null;&lt;br&gt;         $con = A($controller);&lt;br&gt;         $functions = get_class_methods($con);&lt;br&gt;         //排除部分方法&lt;br&gt;         $inherents_functions = array('_initialize','__construct','getActionName','isAjax','display','show','fetch','buildHtml','assign','__set','get','__get','__isset','__call','error','success','ajaxReturn','redirect','__destruct', '_empty');&lt;br&gt;         foreach ($functions as $func){&lt;br&gt;             if(!in_array($func, $inherents_functions)){&lt;br&gt;                 $customer_functions[] = $func;&lt;br&gt;             }&lt;br&gt;         }&lt;br&gt;         return $customer_functions;&lt;br&gt;     }</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">';&lt;br&gt;         print_r($data);&lt;br&gt;     }&lt;br&gt; &lt;br&gt;     //获取所有控制器名称&lt;br&gt;     protected function getController($module){&lt;br&gt;         if(empty($module)) return null;&lt;br&gt;         $module_path = APP_PATH . '/' . $module . '/Controller/';  //控制器路径&lt;br&gt;         if(!is_dir($module_path)) return null;&lt;br&gt;         $module_path .= '/*.class.php';&lt;br&gt;         $ary_files = glob($module_path);&lt;br&gt;         foreach ($ary_files as $file) {&lt;br&gt;             if (is_dir($file)) {&lt;br&gt;                 continue;&lt;br&gt;             }else {&lt;br&gt;                 $files[] = basename($file, C('DEFAULT_C_LAYER').'.class.php');&lt;br&gt;             }&lt;br&gt;         }&lt;br&gt;         return $files;&lt;br&gt;     }&lt;br&gt; &lt;br&gt;     //获取所有方法名称&lt;br&gt;     protected function getAction($module, $controller){&lt;br&gt;         if(empty($controller)) return null;&lt;br&gt;         $content = file_get_contents(APP_PATH . '/'.$module.'/Controller/'.$controller.'Controller.class.php');&lt;br&gt;         preg_match_all(&quot;/.*?public.*?function(.*?)\(.*?\)/i&quot;, $content, $matches);&lt;br&gt;         $functions = $matches[1];&lt;br&gt;         //排除部分方法&lt;br&gt;         $inherents_functions = array('_initialize','__construct','getActionName','isAjax','display','show','fetch','buildHtml','assign','__set','get','__get','__isset','__call','error','success','ajaxReturn','redirect','__destruct','_empty');&lt;br&gt;         foreach ($functions as $func){&lt;br&gt;             $func = trim($func);&lt;br&gt;             if(!in_array($func, $inherents_functions)){&lt;br&gt;                 $customer_functions[] = $func;&lt;br&gt;             }&lt;br&gt;         }&lt;br&gt;         return $customer_functions;&lt;br&gt;     }</pre>

AD:真正免费,域名+虚机+企业邮箱=0元

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

EditPlus chinesische Crack-Version

EditPlus chinesische Crack-Version

Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version

WebStorm-Mac-Version

WebStorm-Mac-Version

Nützliche JavaScript-Entwicklungstools

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor