Adam
Adam

Reputation: 9449

Hide Codeigniter controller name from URL with multiple controllers

I'm using the following code in my routes.php to hide the controller name from the URL structure:

$route['(:any)'] = "auth/$1";

It works great, but my problem is this: When I want to access another controller, it seems to treat it as a function of the hidden controller.

So for example. I have

http://mysite.com/controller1/somefunction

which turns into:

http://mysite.com/somefunction

What if I want to access:

http://mysite.com/jsonfunction/anotherfunction/

How can I access the other controller while keeping the other one hidden? I really don't want visitors seeing http://mysite.com/maincontroller/ that's just redundant!

Upvotes: 2

Views: 3440

Answers (1)

bottleboot
bottleboot

Reputation: 1699

You are going to have to define your routes more specific I am afraid. You can still use:

$route['(:any)'] = "auth/$1";

But it will probably go to the button of your list of routes.

if you want other routes to be added that overrule that one you'll have to place them on top. For example like this:

$route['login'] = "auth/login";
$route['varY'] = "controllerX/varY";
$route['varY/(:any)'] = "controllerX/varY/$1";
$route['foobar'] = "controller/method";
$route['(:any)'] = "auth/$1";

See this document for more info and future reference: http://codeigniter.com/user_guide/general/routing.html

Upvotes: 2

Related Questions