Welcome Guest, Not a member yet? Register   Sign In
Move Error functions to a Controller
#11

[eluser]Pascal Kriete[/eluser]
Wow, I can't believe you found this.

Glad to hear it works for you Smile .

[Edit: Code updated to reflect your change. ]
#12

[eluser]mattalexx[/eluser]
[quote author="inparo" date="1226727271"]Wow, I can't believe you found this.[/quote]

Oh, it's all over Google. ;-)
#13

[eluser]mattalexx[/eluser]
I wonder if there's a way to 404-ize the first request too..

See attached example.
#14

[eluser]Pascal Kriete[/eluser]
Unfortunately not. It might me more correct to send a 301 though.
Code:
header("Location: ".$redirect, TRUE, 301);

FWIW, mobile me does a redirect to an error page and it throws a 302 (and no 404 - ever), but they change the url as well.
#15

[eluser]mattalexx[/eluser]
[quote author="inparo" date="1226768969"]It might me more correct to send a 301 though.[/quote]

As long as the Google spider doesn't get confused, I'm not worried about it. If a page has "moved permanently" to a "page not found", it seems reasonable to believe that Google will throw that URL into the 404 pile, right?
#16

[eluser]Pascal Kriete[/eluser]
I would assume so, yes.
#17

[eluser]dimethroxy[/eluser]
Sorry to bring this thread back to life but is this the definitive solution to using a controller for error handling ?
#18

[eluser]Pascal Kriete[/eluser]
No, there is no definitive solution. This is just something I thought of a long time ago.

Lately I've been using routes to do this. Meaning I route all controllers, and at the end I add a catch-all route to a 404 controller:
Code:
$route['.*'] = 'error/not_found';

There are a few other solutions by overriding the router, or modifying codeigniter.php.

In most applications 404 pages shouldn't be all too complex anyways [Yahoo Performance Rules].
#19

[eluser]dakta[/eluser]
Just found this thread (thanks, Google), and would like to thank you for saving me a tremendous amount of hassle.

Just one thing (besides minor renaming for CI 2.x compatibility, which I already did): how do you use this to catch PHP errors? I can currently catch 404 errors just fine, but forcing PHP to throw an error causes the default error handler page to be used. I have already created a new condition in the _remap() function, added a relevant handler function (_error_php()), but it doesn't seem to have worked.

Regards,
- Dakota




Theme © iAndrew 2016 - Forum software by © MyBB