Welcome Guest, Not a member yet? Register   Sign In
Routing tricks
#1

[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! :-)
#2

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

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




Theme © iAndrew 2016 - Forum software by © MyBB