Reputation: 3696
I want address of my website user is mydomain.com/username/. But it seems very difficult to me using codeIgniter.Please help me what is best way to do it.
mysite.com/profile?user=username is current url of profile but i want this mysite.com/username
please help me and I'm not good english speaker so I'm sorry if you not understand my question.
Upvotes: 0
Views: 234
Reputation: 12207
In your routes.php
file route every existing controller (you should have atleast one) to itself. For example if you have controller main
in main.php
file route it:
$route['main'] = "main";
$route['main/(:any)' = "main/$1";
The reason why you should route it twice is because you must make sure that opening http://yoursite/main
works as well as http://yoursite/main/my_method/
etc. Do this for every other controller you have.
The next step is to route everything else to your users controller. For example you have a profile
method that has 1 argument - the username.
$route['(:any)'] = "users/profile/$1";
So now you will have everything else routed to users/profile/username
.
One thing to remember is that the topmost priority goes higher in the routes.php
file so your routes file should look something like:
$route['main'] = "main";
$route['main/(:any)' = "main/$1";
$route['users'] = "main";
$route['users/(:any)' = "main/$1";
$route['(:any)'] = "users/profile/$1";
See if that works!
Upvotes: 2
Reputation: 184
You can use the CI routing
In your route.php file, select all your users and create a route for each :
$aUsers = $this->oDb->getAllUsers();
foreach($aUsers as $oUser) {
$route[$oUser->username] = "profile/" . $oUser->username;
}
It should work.
Upvotes: 0