CodeIgniter Forums
Getting Controller name in post_controller_constructor hook - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Getting Controller name in post_controller_constructor hook (/showthread.php?tid=3699)



Getting Controller name in post_controller_constructor hook - El Forum - 10-17-2007

[eluser]Majd Taby[/eluser]
Hey, in hooks.php, is there a way to get the controller name? I have a hook that redirects to a login page, but i want to know the name of the controller it is redirecting from, such that when the user logs in successfully, he can be redirected there.


Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]PERR0_HUNTER[/eluser]
I wonder if you ever got a solution to this problem


Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]WanWizard[/eluser]
You could use the output of debug_backtrace() to find what has called your method.


Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]Jelmer[/eluser]
You might try this:
Code:
$ci = get_instance();
$controller_name = get_class($ci);

The CI superobject is your controller (extending CI_Base and Controller).


Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]danmontgomery[/eluser]
Code:
$CI =& get_instance();
$class = $CI->router->class;



Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]PERR0_HUNTER[/eluser]
Wonderful! One last question Smile is there any way of also knowing what Method is being called ? right now I'm exploring the URI class to see if there's anyway I can get this info, also I came across this Filter System which I think does what the original author and I are intending to do http://codeigniter.com/wiki/Filters_system/


Getting Controller name in post_controller_constructor hook - El Forum - 07-26-2010

[eluser]danmontgomery[/eluser]
Code:
$CI =& get_instance();
$method = $CI->router->method;