Search code examples
phpcodeignitercodeigniter-2

CodeIgniter: How to get Controller, Action, URL information


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', 
  '...'=>'...'
)

Solution

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