<?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. 在 Tomcat 中自定义 404 页面(简单配置)

      打开 Tomcat 中的 web.xml,(tomcat/conf/web.xml) 添加如下代码: <error-page>  <error-code>404</e ...

  2. Centos7 升级 Ruby

    Centos7通过yum 安装的Ruby 是2.0版本.版本较低,需要升级到2.5以上版本. #yum 安装ruby yum install ruby #查看ruby版本 ruby -v 以下开始升级 ...

  3. Docker Swarm 介绍 or 工作原理

    Docker Swarm 介绍 Swarm 简介 Swarm是Docker公司自研发的容器集群管理系统,Swarm在早期是作为一个独立服务存在,在Docker Engine v1.12中集成了Swar ...

  4. Linux 高级文件管理

    1.标准输出(ls -l /dev/stdin 0 ),标准输入(ls -l /dev/stdout 1 ),错误输出(ls -l /dev/stderr 2 ). 2.ls /etc/passwd  ...

  5. 使用pm2-zabbix监控node工程

    环境 centos 7 zabbix 3.2.6 node 4.4.3 安装 # wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix ...

  6. Splay详解

    平衡树实际很简单的 以下讲解都以Luogu P3369 [模板]普通平衡树为例 我不会带指针的Splay,所以我就写非指针型的Splay Splay是基于二叉查找树(bst)实现的 什么是二叉查找树呢 ...

  7. 绘制COCO数据集结果

    import os import time import datetime import mmcv import cv2 as cv import json import numpy as np im ...

  8. 牛客-数据库SQL实战

    查找最晚入职员工的所有信息 CREATE TABLE `employees` ( `emp_no` ) NOT NULL, `birth_date` date NOT NULL, `first_nam ...

  9. 激活Pychram

    最近更新了Intellij IDEA到2018.1.5之后,使用之前的授权服务器(http://idea.imsxm.com)会提示Outdated License Server Detected,大 ...

  10. [IDE - Eclipse] JSP报错:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

    是因为Eclipse的Web项目不自动引入相关jar包. Right Click on the Project ❯ Properties ❯ Project Facets. You would be ...