php - Codeigniter 如何在当前 Controller 中获取所有/特定方法

标签 php codeigniter class methods controller

我知道这段代码:

$this->router->fetch_class(); // get current controller name
$this->router->fetch_method(); // get current method name

我想做的是获取当前 Controller 或特定 Controller 中可用的所有方法。任何人都有同样的经历吗?谢谢。

解决方案

我创建助手来列出特定 Controller 中的所有方法

function list_this_controllers_method_except($controller, $except = array())
{
    $methods = array();

    foreach(get_class_methods($controller) as $method)
    {
        if (!in_array($method, $except))
        {
            $methods[] = $method;
        }
    }

    return $methods;
}

最佳答案

您可以使用 native php 来获取类方法

get_class_methods($this);

$this 是被调用的 Controller

仅示例

class user extends CI_Controller {

    public function __construct() {

                #-------------------------------
                # constructor
                #-------------------------------

                parent::__construct();

                var_dump(get_class_methods($this));

            }

}

阅读文档

http://php.net/manual/en/function.get-class-methods.php

关于php - Codeigniter 如何在当前 Controller 中获取所有/特定方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28759200/

相关文章:

php - while 循环中偶尔出现奇怪的重复 echo

php - 使用数据库中的数据填充 LaravelCollective select

php - Codeigniter 更改查询

c++ - 如何为不同的类声明相同的对象名称?

javascript - 阅读类(class)并使用 javascript 或 jquery 应用 css

php - 在 MAMP 3 中启用日志

php - AWS Elastic Beanstalk for PHP 通过 CLI 上传 ZIP off 应用程序

php - CodeIgniter HMVC 扩展了 MX_Controller,无法正确使用 get_instance

php - 选择选项默认值中的 Codeigniter 不起作用

php - 声明函数时 'static'是什么意思