<?php
namespace Admin\Controller;
use Think\Controller;
class AuthorController extends PublicController {
    /**
     * @note 获取控制器和action存放数据库
     */
    public function index(){
        $modules = array('Admin');  //模块名称
        $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(
                        'controller' => $controller,
                        'action' => $action,
                        'desc'=>$this->get_cc_desc($module,$controller,$action)
                    );
                    $i++;
                }
            }
        }

$result = D('Author')->updata($data);
        $this->assign('stat',$result);
        $this->display();
    }

/**
     * @note 获取控制器
     * @param $module
     * @return array|null
     */
    protected function getController($module){
        if(empty($module)) return null;
        $module_path = APP_PATH . '/' . $module . '/Controller/';  //控制器路径
        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;
    }

/**
     * @note 获取方法
     *
     * @param $module
     * @param $controller
     *
     * @return array|null
     */
    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];

//排除部分方法
        $inherents_functions = array('login','logout','uppassword','_initialize');//如有排除方法添加此数组
        $inherents_functions = array();
        foreach ($functions as $func){
            $func = trim($func);
            if(!in_array($func, $inherents_functions)){
                if (strlen($func)>0)   $customer_functions[] = $func;
            }
        }
        return $customer_functions;
    }

/**
     * @note 获取函数的注释
     *
     * @param $module Admin
     * @param $controller Auth
     * @param $action index
     *
     * @return string 注释
     *
     */
    protected function get_cc_desc($module,$controller,$action){
        $desc=$module.'\Controller\\'.$controller.'Controller';

$func  = new \ReflectionMethod(new $desc(),$action);
        $tmp   = $func->getDocComment();
        $flag  = preg_match_all('/@note(.*?)\n/',$tmp,$tmp);
        $tmp   = trim($tmp[1][0]);
        $tmp   = $tmp !='' ? $tmp:'无';
        return $tmp;
    }
}

thinkphp获取后台所有控制器和action的更多相关文章

  1. Web APi之控制器选择Action方法过程(九)

    前言 前面我们叙述了关于控制器创建的详细过程,在前面完成了对控制器的激活之后,就是根据控制器信息来查找匹配的Action方法,这就是本节要讲的内容.当请求过来时首先经过宿主处理管道然后进入Web AP ...

  2. Struts1.x下使用jquery的Ajax获取后台数据

        jquery中有多种Ajax方法来获取后台数据,我使用的是$.get()方法,具体的理论我不解释太多,要解释也是从别的地方copy过来的.下面就介绍我的项目中的实现方法.     前台页面: ...

  3. PHP获取项目所有控制器方法名称

    PHP获取项目所有控制器方法名称 //获取模块下所有的控制器和方法写入到权限表 public function initperm() { $modules = array('admin'); //模块 ...

  4. struts2:JSON在struts中的应用(JSP页面中将对象转换为JSON字符串提交、JSP页面中获取后台Response返回的JSON对象)

    JSON主要创建如下两种数据对象: 由JSON格式字符串创建,转换成JavaScript的Object对象: 由JSON格式字符串创建,转换成JavaScript的List或数组链表对象. 更多关于J ...

  5. 通过form表单上传文件获取后台传来的数据

    小伙伴是不是遇到过这样的问题,通过submit提交form表单的时候,不知怎么获取后台传来的返回值.有的小伙伴就会说你不会发送ajax,其实也会.假如提交的form表单中含有文件,怎么办? 步骤1:想 ...

  6. 如何通过submit提交form表单获取后台传来的返回值

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34651764/article/details/76373846 小伙伴是不是遇到过这样的问题 ...

  7. 使用form表单提交请求如何获取后台返回的数据?

    问题描述 一般的form表单提交是单向的:只能给服务器发送数据,但是无法获取服务器返回的数据,也就是无法读取HTTP应答包. 想要真正的半双工通讯一般需要使用Ajax, 但是Ajax对文件传输也很麻烦 ...

  8. Codeigniter 获取当前的控制器名称和方法名称

    在Codeigniter 可以通过下面两个方法获取当前的控制器名称和方法名称 $this->router->fetch_class(); $this->router->fetc ...

  9. 前后端分离项目获取后端跨控制器获取不到session

    最近做前后端分离项目(.net core web api  +vue)时,后台跨控制器不能获取到session.由于配置的是共享的session.本来以为是共享session出了问题,就在共享sess ...

随机推荐

  1. Docker Registry V2 Garbage Collection

    运行 docker run --rm -v /nfs1/docker/registry:/var/lib/registry registry:2.5.1 garbage-collect -d /roo ...

  2. 简单js 切换左侧栏目的样式

    这是html代码,里面写了left.html <div id='mydiv'> <a class='qwe'>1</a> <a class='qwe'> ...

  3. Bugku-CTF之域名解析(听说把 flag.baidu.com 解析到123.206.87.240 就能拿到flag)

    Day 7 域名解析 50 听说把 flag.baidu.com 解析到123.206.87.240 就能拿到flag    

  4. 剑指offer(13)调整数组顺序使奇数位于偶数前面

    题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 题目分析 判断是 ...

  5. centos7 keepalived 配置高可用

    ! Configuration File for keepalived global_defs { notification_email { xaioqiang.he@xinboxinmo.com } ...

  6. 【虚拟机】解决网络适配器没有 VirtualBox Host-Only Ethernet Adapter 问题

    下面以windows系统来演示重新安装 VirtualBox Host-Only Ethernet Adapter的方法 1.“win+r”输入“devmgmt.msc”,出现如下界面: 2.点击菜单 ...

  7. NYOJ_1274_信道安全 -

    别琢磨中间过程,我也整不清楚,死记住模板吧 #include <stdio.h> #include <string.h> #include <queue> usin ...

  8. centos 打印机安装方法

    这里安装的是hplip 1.首先确定cups有没有安装 没有的话 yum install cups 安装 2.安装 hplip yum install -y hplip hplip-* 3执行 hp- ...

  9. pytest文档14-函数传参和firture传参数request

    前言 为了提高代码的复用性,我们在写用例的时候,会用到函数,然后不同的用例去调用这个函数. 比如登录操作,大部分的用例都会先登录,那就需要把登录单独抽出来写个函数,其它用例全部的调用这个登陆函数就行. ...

  10. 整合SpringData JPA

    ORM(Object Relational Mapping): 1).编写一个实体类(bean)和数据表进行映射,并且配置好映射关系: //使用JPA注解配置映射关系 @Entity //告诉JPA这 ...