作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我知道这段代码:
$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));
}
}
阅读文档
关于php - Codeigniter 如何在当前 Controller 中获取所有/特定方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28759200/
我是一名优秀的程序员,十分优秀!