• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routing Question (:any)

#1
[eluser]CI-Newb[/eluser]
Hello CI Forum & Coders! I would like the following url to display a users profile:
Code:
http://www.website.com/username-here
.
The following is what I am trying to use to acomplish this.
Code:
$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!

#2
[eluser]InsiteFX[/eluser]
Make sure that it is the very last route in the file.

#3
[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:

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

Or something like it...

#4
[eluser]CroNiX[/eluser]
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.

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

#5
[eluser]jotorres1[/eluser]
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.

http://www.jotorres.com/2011/12/remappin...deigniter/

Hope it helps.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.