Forcing CodeIgniter to show 404 page instead of any other error like 1064 |
[eluser]Unknown[/eluser]
How can replace error pages like Code: A Database Error Occurred
[eluser]Aken[/eluser]
You should never have query errors like this on your production website, nor should you ever hide them like nothing happened. Fix the problem, don't suppress it.
[eluser]Otemu[/eluser]
Hi, What Aken said above is an essential thing to do, as I kind of misread the question. Fix your errors!!!!! If however a user requests a page and your database returns no results then you would need to run a check on the query to test if it returns any results, for example you could have code like this in your model ($query->num_rows() > 0) { // query successful return true } else { // query failed return false } Then in your controller have it check if this is true or false, if false then run 404 function. Good example here
[eluser]boltsabre[/eluser]
Quote:Then in your controller have it check if this is true or false, if false then run 404 function. I personally like the handle the 404 direct in my model, saves running more if statements in the controller, keeping them leaner. Obviously this is just a personal preference and not suited to everyone nor every situation. In some situations you certainly want to return false to your controller and display/do something rather than show a 404 :-) I have built my own helper file with a function called page_not_found($var=null), which basically just throws a 404 http header, redirects to my 404 page, and exits. I'm at work and don't have my code base here, but it's something like this (p.s. I've autoloaded the helper) Code: function page_not_found($var = null){ And then in my model, instead of returning false, I just call this: Code: ($query->num_rows() > 0) { |
Welcome Guest, Not a member yet? Register Sign In |