![]() |
User Profile URL - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: User Profile URL (/showthread.php?tid=6490) Pages:
1
2
|
User Profile URL - El Forum - 03-01-2008 [eluser]~Chris~[/eluser] any tips on how i can make user URL's for example http://www.example.com/username will display a dynamic page containing the user's profile. User Profile URL - El Forum - 03-01-2008 [eluser]~Chris~[/eluser] well, im looking at what i wrote and realized it is very vague. I can handle all the dynamic page and everything. what i basically need to know is how to set the controller to know if its a username in the url and not to try and call a controller by that name. so that when u go to www.example.com/username it will not throw a 404. and if you go to www.example.com/realcontroller it will not try and load the user profile controller, but load the real controller. User Profile URL - El Forum - 03-01-2008 [eluser]m4rw3r[/eluser] Why not use a controller named user (and route it to user/display/[username])? Then you won't have this problem. Use the routes.php config file to route the user to the right controller function (http://ellislab.com/codeigniter/user-guide/general/routing.html). User Profile URL - El Forum - 03-01-2008 [eluser]vadivelan[/eluser] I have yet to complete reading CI, still I believe the following approach seems good. If there is no controller associated with a particular request then a 404 is thrown and request finally reach the application/error/error_404.php Here we can verify how many segments that actual request carry. If the total segment is only one, collect that segment using uri->segment(1) and check against your users ( db / collection , array ) and proceed further. But the issue is, I don't know how to use the CI's libraries ( uri - to count the segement and any other libraries to do some process ) in application/error/error_404.php template. Because we cannot access CI resources outside controller, I tried with $CI = &getInstance;();, but without success. If we know how to use CI's libraries outside controller especially in /application/error/error_404, I think this is done. User Profile URL - El Forum - 03-01-2008 [eluser]~Chris~[/eluser] yes, i was thinking upon the same line as you at first vadivelan. tapping into the error page, but i thought about the same issues too. I dont want to use a user controller because i want to have as short a url as possible. I was thinking about using htaccess but it would just interfere with the codignitor mod rewrites. I was also thinking about modding the core to handle whether it was an actual 404 or a user uri, but I do not really want to do that, because it is unclean. maybe if there was a good hook to use or something. User Profile URL - El Forum - 03-01-2008 [eluser]vadivelan[/eluser] Second approach is to use a hook. 1. Create a pre-controller hook 2. From that hook access the total number of segments ( using uri library ). 3. If total segment is one, collect the uri_path (using uri's uri_string ) 4. Check if this related to any real path using file's set_realpath. If this doesn't resolve to valid path then you shall verify and generate your user profile or redirect to their profile page. if( $this->uri->total_rsegments() == 1 ) { $uristring = $this->uri->uri_string(); if( ! $this->file->set_realpath('./system/application/'.$uristring . ".php" ) { echo(" got it"); } } But like my above post, I don't know how to access CI's libraries within hook. lol. User Profile URL - El Forum - 03-01-2008 [eluser]vadivelan[/eluser] I agree with you Chris, these are not clean approaches. These approaches will break in a production environment over the period of time and not maintainable. User Profile URL - El Forum - 03-01-2008 [eluser]~Chris~[/eluser] I found this. I may be able to use its concept. http://ellislab.com/forums/viewthread/70848/ User Profile URL - El Forum - 03-01-2008 [eluser]Michael Wales[/eluser] Just establish a route for all of the URLs you do know - for a fact. Then setup an open route to handle anything else (your users). Code: $routes['user/register'] = 'user/register'; User Profile URL - El Forum - 03-03-2008 [eluser]~Chris~[/eluser] ah yes michael wales, thank you very much. I was making it much more complicated than i needed to. p.s. Thanks for Erkana auth. |