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_方法()method。

$this->>router->fetch_method()将返回
索引

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