CodeIgniter Forums
routing question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: routing question (/thread-26171.html)

Pages: 1 2


routing question - El Forum - 01-07-2010

[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!


routing question - El Forum - 01-07-2010

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

http://ellislab.com/codeigniter/user-guide/general/routing.html


routing question - El Forum - 01-07-2010

[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.


routing question - El Forum - 01-07-2010

[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.


routing question - El Forum - 01-07-2010

[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";



routing question - El Forum - 01-07-2010

[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.


routing question - El Forum - 01-07-2010

[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


routing question - El Forum - 01-07-2010

[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.


routing question - El Forum - 01-07-2010

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

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


routing question - El Forum - 01-07-2010

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