Codeigniter在帮助程序中获取控制器名称
我有一个用于记录日志的自定义助手 在助手的一个函数中,我需要获取被调用的控制器的名称。有办法吗Codeigniter在帮助程序中获取控制器名称,codeigniter,Codeigniter,我有一个用于记录日志的自定义助手 在助手的一个函数中,我需要获取被调用的控制器的名称。有办法吗 我不能依赖uri段,因为一些控制器位于子文件夹中,而助手被广泛使用。您可以在CI2.x中使用以下内容 $this->router->fetch_class(); 您可能需要首先获取CI超级变量$this的实例,在这种情况下。使用以下命令: $ci =& get_instance(); $ci->router->fetch_class(); 还有一个$ci->rout
我不能依赖uri段,因为一些控制器位于子文件夹中,而助手被广泛使用。您可以在CI2.x中使用以下内容
$this->router->fetch_class();
您可能需要首先获取CI超级变量$this的实例,在这种情况下。使用以下命令:
$ci =& get_instance();
$ci->router->fetch_class();
还有一个
$ci->router->fetch_方法()如果出于任何原因需要调用的方法的名称,请使用code>method。$this->>router->fetch_method()如果执行以下操作,code>将返回索引
:
class Someclass extends CI_Controller {
function index(){
$this->edit();
}
function edit(){
$this->router->fetch_method(); //outputs index
}
}
这应该有效(不确定它是否在帮助程序中有效):
您还可以使用URI类
$ci = & get_instance();
$ci->uri->segment(1) // That stands for controller
$ci->uri->segment(2) // That stands for method
$ci = & get_instance();
$ci->uri->segment(1) // That stands for controller
$ci->uri->segment(2) // That stands for method