Welcome Guest, Not a member yet? Register   Sign In
get controller and method in helper
#1

[eluser]Unknown[/eluser]
In my core controller constructor I call a helper function. I was wondering if there is a way to get the controller and method that has called the helper?

At the moment I am doing it on URL segments but this doesn't always work because if there is a route in place the URL won't reflect the controller being called.

Thanks for any help
#2

[eluser]Aken[/eluser]
Code:
$controller = $this->router->fetch_class();
$method = $this->router->fetch_method();

Note that the URI class also has functions for returning info for both pre- and post-routed URLs.
#3

[eluser]mejlo[/eluser]
Aken ;-)
Code:
function some_helper()
{
...
$CI = get_instance();
$controller = $CI->router->fetch_class();
$method = $CI->router->fetch_method();
...
}
#4

[eluser]Aken[/eluser]
You forgot to reference the CI object.

Code:
$CI =& get_instance();

And yes, that's what you'd do if it was in a helper. I wasn't sure if he wanted it in his constructor or helper, so I just exampled with $this. He should be able to translate it either way at that point.




Theme © iAndrew 2016 - Forum software by © MyBB