CodeIgniter Forums
Routing tricks - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Routing tricks (/thread-4324.html)



Routing tricks - El Forum - 11-18-2007

[eluser]Base Willy[/eluser]
Hi again!

This time we (I hope we, not just me, myself and I like it was last timeSmile) will talk about routing.

I have a controller named user and it has a function called profile. So we could se user's profile at /user/profile/user_login
What I want now is to do so that we could see that profile not only there but else at site.com/user_login.

I did it like this: (config/routes.php)
Code:
$route['((photos|blogs).+)'] = "$1";
$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";

We can't just route everything to user/profile because there are another controllers (photos and blogs in example) and that's what the first route for.

It seems to work fine but I wanted to discuss it and see if it's a good solution or there is a better way.

Viva la CI! :-)


Routing tricks - El Forum - 12-12-2007

[eluser]hotmeteor[/eluser]
[quote author="Base Willy" date="1195403579"]Hi again!

This time we (I hope we, not just me, myself and I like it was last timeSmile) will talk about routing.

I have a controller named user and it has a function called profile. So we could se user's profile at /user/profile/user_login
What I want now is to do so that we could see that profile not only there but else at site.com/user_login.

I did it like this: (config/routes.php)
Code:
$route['((photos|blogs).+)'] = "$1";
$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";

We can't just route everything to user/profile because there are another controllers (photos and blogs in example) and that's what the first route for.

It seems to work fine but I wanted to discuss it and see if it's a good solution or there is a better way.

Viva la CI! :-)[/quote]

How do you link to that user's profile that way? Do you use:

Code:
<a href="http://site.com/user/profile/user_login">Profile</a>

or somehow do:

Code:
<a href="http://site.com/user_login">Profile</a>



Routing tricks - El Forum - 12-12-2007

[eluser]Base Willy[/eluser]
site.com/user