![]() |
Trick to delete controller in query string - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Trick to delete controller in query string (/showthread.php?tid=13671) |
Trick to delete controller in query string - El Forum - 12-01-2008 [eluser]Cahyono[/eluser] I try to change http://localhost/index.php?c=welcome&m=home into http://localhost/index.php?m=home So I want to delete c=welcome from URL so that shorter. After trial and error, I found like this: in file system\application\config\routes.php : Code: $route['default_controller'] = "welcome"; in file system\Libraries\Router.php search on function _validate_request($segments): Code: // Can't find the requested controller... Add above so become this below: Code: $segments[0] = $this->default_controller; That's it. It's work fine to me. Trick to delete controller in query string - El Forum - 12-01-2008 [eluser]Jelmer[/eluser] That's by far not the best way to do this, in fact it's a pretty bad one since you'd have to edit your /system/ files on every CI update. Also it's bad because there's a pretty simple way to do the same within the system\application\config\routes.php file. If I understand you correctly, you want every request to be handled by the same default controller if no controller can be found. While there are I believe even better ways to do this, the way I solved this problem was by first registering all my other controllers and then closing with the default router which is set to 'welcome' by the final rule: Code: $route[':any'] = 'welcome'; All the others you'll have to set before that rule by adding them: Code: $route['other_controller/(:any)'] = 'other_controller/$1'; Or with 2 rules if you want it to work without the function set as well: Code: $route['other_controller/(:any)'] = 'other_controller/$1'; I'll admit it's a bit more work, but keeping the system files without edits will save you many headaches when updating CI to the latest version. Trick to delete controller in query string - El Forum - 12-01-2008 [eluser]Cahyono[/eluser] Yes you right. Thanks for your suggestion. Trick to delete controller in query string - El Forum - 12-02-2008 [eluser]Thorpe Obazee[/eluser] [quote author="Jelmer" date="1228206340"]That's by far not the best way to do this, in fact it's a pretty bad one since you'd have to edit your /system/ files on every CI update. Also it's bad because there's a pretty simple way to do the same within the system\application\config\routes.php file. If I understand you correctly, you want every request to be handled by the same default controller if no controller can be found. While there are I believe even better ways to do this, the way I solved this problem was by first registering all my other controllers and then closing with the default router which is set to 'welcome' by the final rule: Code: $route[':any'] = 'welcome'; All the others you'll have to set before that rule by adding them: Code: $route['other_controller/(:any)'] = 'other_controller/$1'; Or with 2 rules if you want it to work without the function set as well: Code: $route['other_controller/(:any)'] = 'other_controller/$1'; I'll admit it's a bit more work, but keeping the system files without edits will save you many headaches when updating CI to the latest version.[/quote] Could it be done to use one routing rule to get this? Code: $route['other_controller/(:any)'] = 'other_controller/$1'; |