gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 22:53:53 25 4
gpt4 key购买 nike

我知道这段代码:

$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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com