Codeigniter get controller name in helper

后端 未结 4 608
醉酒成梦
醉酒成梦 2021-02-08 04:13

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 i

4条回答
  •  生来不讨喜
    2021-02-08 04:53

    You can use the following in CI2.x

    $this->router->fetch_class();
    

    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();
    

    There's also a $ci->router->fetch_method(); method if you need the name of the method called for any reason.

提交回复
热议问题