CodeIgniter Forums

Full Version: routing question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]dadamssg[/eluser]
Is it possible(with CodeIgniter) to set up a site similar to twitter in that you can find different profiles at http://example.com/aporofile. I have a database full of profile users and their information but would love to instead of this

http://www.mysite.com/myfolder/profile.php?id=Bob

routed to this

http://www.mysite.com/Bob

But im not seeing how thats possible if i have folders at my root like 'myfolder' in my example. Hope that made sense!

El Forum

[eluser]flaky[/eluser]
you can achieve that with routes

http://ellislab.com/codeigniter/user-gui...uting.html

El Forum

[eluser]WebsiteDuck[/eluser]
I would use http://www.mysite.com/user/Bob when setting up your routes to avoid ambiguity. You may have to disallow certain usernames if you don't, depending on how you have your site set up.

El Forum

[eluser]dadamssg[/eluser]
Yeah i think its going to be easier if i use '/user/' bkaxrf.

Flaky, i read the guide and don't see how i can use a username where i want it because where i want it is where classes usually go...thats why i asked.

El Forum

[eluser]flaky[/eluser]
you would achive that like this, it's very basic far from perfect or for use in production

Code:
//redirect to controller user
$route[":any"] = "user/profile";

El Forum

[eluser]WebsiteDuck[/eluser]
Code:
$route[':any'] = "usercontroller/viewprofile/$1";

This should do what you want, although I haven't tested it. You'll have to change the controller and function, obviously.

El Forum

[eluser]dadamssg[/eluser]
that makes sense...let me know if this makes sense

1. reserve some usernames for my folder names
2. have that route to like you both wrote
3. in my viewprofile page i would need some code that would check to see if that username exists and if not check to see if its a folder and send to that folder.

im just worried about my folders that i have at the root being mistaken as users

El Forum

[eluser]dadamssg[/eluser]
im learning on my hosted account which already has my website coded in the non-framework/procedural way so i have folders where i store all of my files in. So for example i store just about all of my files in a folder ive called 'main'

http://www.myexample.com/main/index.php

i don't want that to be redirected to a profile page.

El Forum

[eluser]dadamssg[/eluser]
or this either...

http://www.myexample.com/main/event.php?id=234

El Forum

[eluser]flaky[/eluser]
it is far better to use ‘/user/' as bkaxrf said
Pages: 1 2