Codeignator在助手中获取控制器名称 [英] Codeigniter get controller name in helper
问题描述
我有一个自定义的帮助器,我用于日志记录。
I have a custom helper that i use for logging.
在帮助器的一个函数中,我需要得到被调用的控制器的名称。有办法吗?
Within one of the functions of the helper i need to get the name of the controller that was called. Is there a way to do it?
我不能依赖uri段,因为一些控制器在子文件夹中,并且帮助器已经使用。
I can't rely on uri segments because some controllers are in sub-folders and the helper is used all over.
推荐答案
您可以在CI2.x中使用以下内容
You can use the following in CI2.x
$this->router->fetch_class();
您可能需要获取CI超级变量$ this的实例 - 在这种情况下。使用以下操作:
You may need to get an instance of the CI super variable $this first- in which case. Use the following:
$ci =& get_instance();
$ci->router->fetch_class();
还有一个 $ ci-> router-> fetch_method ;
方法,如果您需要因任何原因调用的方法的名称。
There's also a $ci->router->fetch_method();
method if you need the name of the method called for any reason.
这篇关于Codeignator在助手中获取控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!