stergosz
stergosz

Reputation: 5860

codeigniter routing issue

I had my users profile at

www.domain.com/user/username

and moved it at

www.domain.com/username

but this required to add most classes functions into the routes.php file in the config and if i want to add new features to my app i will need to add all the functions into the routes.php file which doesnt sound good practice...

What is the best way that other deal with it on CodeIgniter ?

Upvotes: 0

Views: 102

Answers (2)

stergosz
stergosz

Reputation: 5860

seems i got the answer

what i did is add the below code for every controller i have

$route['controller'] = "controller";
$route['controller/(:any)'] = "controller/$1";

and this code at the bottom

$route['(:any)'] = "user/$1";

Upvotes: 0

Shomz
Shomz

Reputation: 37711

Perhaps, you can do it the other way round - make a whitelist of usernames that can't be taken (those would be names of your controllers, like admin, contact, etc...) and route anything except the whitelist items.

Upvotes: 1

Related Questions