My application is designed to provide a single profile page for each user, with the 3rd segment being the user’s ID.
example.com/profile/page/1
Assuming user 1 is “Jon Jovi”, using CI’s routing I would like to generate this URI
example.com/jon_jovi
Is it possible to send this user’s ID to config/routes.php, run a function to extract user 1’s info from database and insert it like
$route['profile/page/$row->id'] = $row->first_name . '_' . $row->last_name;
Any thought or suggestions on how to do this are much appreciated – thanks.
If you want to the “client” url to be in format
base_url/[username], you will probrably need to grab the username some regex routing, like$route['([a-zA-z_]+)'] = "profile/page/$1";, and look on your database for that user.Another solution would be appending the id to the url, like
base_url/[username]/[id]. For this, the regex$route['([a-zA-z_]+)/([0-9+])'] = "profile/page/$2";would pass the id as the first parameter for the page function of Profile controller.Check the Documentation for more details on dynamic routing: http://codeigniter.com/user_guide/general/routing.html