CodeIgniter Forums
Way to get current object and method by URI? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Way to get current object and method by URI? (/showthread.php?tid=58344)



Way to get current object and method by URI? - El Forum - 06-04-2013

[eluser]ShoeLace1291[/eluser]
I'm looking for a function that would tell me the current object and method by way of the URI. Normally, I would use $this->uri->uri_string(), however, I do not want to pass any "dynamic" segments. For example, a URI of 'products/shoes/123', would be 'products/view_product'.

I want to be able to do this so I can create a config file containing page titles... since I use a model to output my page header. It is called from MY_Controller.php in the construct. For example: $this->template->overall_header($title = "View Product")... but in the construct, it would be $this->template->overall_header($title = $this->config->item($object_method_string));

Anybody have any solutions? Thanks for your time.


Way to get current object and method by URI? - El Forum - 06-05-2013

[eluser]Pert[/eluser]
Something like this maybe?

http://stackoverflow.com/questions/2115913/retrieving-the-name-of-the-current-function-in-php




Way to get current object and method by URI? - El Forum - 06-05-2013

[eluser]CroNiX[/eluser]
Code:
global $RTR;
echo $RTR->fetch_class();
echo $RTR->fetch_method();
echo $RTR->fetch_directory();
$RTR is the router object which is automatically instantiated in CodeIgniter.php as part of the bootstrap process. If you declare it global, you can use it in your controllers, etc.