Welcome Guest, Not a member yet? Register   Sign In
Best way to handle missing url parameters
#1

[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...
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB