Welcome Guest, Not a member yet? Register   Sign In
Routing Question (:any)

Hello CI Forum & Coders! I would like the following url to display a users profile:
The following is what I am trying to use to acomplish this.
$route['(:any)'] = "profile/view/$1";
The problem is this prevents me from accessing any of my other controllers /login/, /logout/ etc. Is there a way to achieve this goal or will I have to add every other controller to the route file above this. ex : [login] -> /login/, [logout] -> logout, etc. Thank you very much for your time and any help that can be provided!

Make sure that it is the very last route in the file.

[eluser]Oscar Dias[/eluser]
That's a question that I have as well. I think the problem with using your solution, besides having to write all routes manually, is that you can't have a user with the username with the same value as your controllers. If you have a controller '/login', you have to prevent users creating the username 'login', otherwise no one will be able to access that user's profile. The same will happen for all your controllers.

I usually end up doing:

$route['user/(:any)'] = "profile/view/$1";

Or something like it...

You can also use a negative rule and exclude controllers. But yeah, once you set up a route, you need to set up routes for all controllers basically, or exclude them from routing like below. Otherwise catch-all routes using (:any) or (.*) will catch everything, including additional segments.

$route['((?!login|logout).*)'] = 'profile/view/$1';
If it's not "login" or "logout" send request to profile/view

There is a simpler way of doing this. By using the _remap function within codeigniter, you can override the: domain/class/method way of getting to a specific method you want.

I wrote about it, so you should take a look.


Hope it helps.

Theme © iAndrew 2016 - Forum software by © MyBB