January 3, 2012
How to get Controller, Action, URL informations with CodeIgniter
Question by noname.cs
I have these urls:
How to get controller name, action name from these urls. I’m codeigniter newbie. Are there any helper function to get this info
Ex:
$params = helper_function( current_url() )
Where $params
becomes something like
array (
'controller' => 'system/settings',
'action' => 'edit',
'...'=>'...'
)
Answer by Jonathan Sampson
You could use the URI Class:
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
I’ve also been told that the following work, but am currently unable to test:
$this->router->fetch_class();
$this->router->fetch_method();
Answer by Starx
As an addition
$this -> router -> fetch_module(); //Module Name if you are using HMVC Component