CodeIgniter Forums
Best way to handle missing url parameters - 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: Best way to handle missing url parameters (/showthread.php?tid=30735)



Best way to handle missing url parameters - El Forum - 05-25-2010

[eluser]jplanet[/eluser]
I found a hack to the CI core that someone posted for handling required parameters, but of course I would like to make sure that the client can keep CI updated in the future. What is the cleanest way to 404 if a user messes with the url and removes required parameters? naturally, I would like to find something cleaner than configuring routes for each and every possible combination and/or writing code in every single function in all controllers...


Best way to handle missing url parameters - El Forum - 05-25-2010

[eluser]frist44[/eluser]
I would definitely say to add code to controllers. Many of my parameters are databases record IDs. As part of the sql statement, I generally check to see if the array came back empty. If so, I redirect to my 404 error, or just back to the home page or something. There's no need to add additional code, just make sure the data is there. Or, if you're not dealing with SQL data arrays, just assign the parameter to a default of FALSE and test if false, meaning that nothing was passed in.