gpt4 book ai didi

Codeigniter 在 helper 中获取 Controller 名称

转载 作者:行者123 更新时间:2023-12-03 18:19:17 24 4
gpt4 key购买 nike

我有一个用于日志记录的自定义助手。

在助手的其中一项功能中,我需要获取被调用的 Controller 的名称。有没有办法做到这一点?

我不能依赖 uri 段,因为一些 Controller 在子文件夹中,并且助手被到处使用。

最佳答案

您可以在 CI2.x 中使用以下内容

$this->router->fetch_class();

在这种情况下,您可能需要首先获取 CI super 变量 $this 的实例。使用以下内容:
$ci =& get_instance();
$ci->router->fetch_class();

还有一个 $ci->router->fetch_method();方法,如果您需要出于任何原因调用的方法的名称。

关于Codeigniter 在 helper 中获取 Controller 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8168662/

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