tags:

views:

977

answers:

2

Hi all,

I have these urls:

.http://backend.domain.com/system/setting/edit/12

.http://backend.domain.com/product/edit/1

How to get controller name, action name from these urls. I'm codeigniter newbie.

are there any helper function to get these info

Ex:

$params = helper_function(current_url())

$params --> array ('controller' => 'system/settings', 'action' => 'edit', '...'=>'...')

Thanks.

+3  A: 

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->class;
$this->router->method;
Jonathan Sampson
because my controller have sub folder, so $this->uri->segment(1) return controller name maybe incorrect. Thanks for your help, I use $this->router to get the informations.
noname.cs
that router class works! thanks.
joetsuihk
+2  A: 

Instead of using URI segments you should do this:

$this->router->fetch_class(); // class = controller
$this->router->fetch_method();

That way you know you are always using the correct values even if you are behind a routed URL, in a sub-domain, etc.

Phil Sturgeon