Welcome Guest, Not a member yet? Register   Sign In
show_404 and 404_override
#5

[eluser]WanWizard[/eluser]
In standard CI, you can't.

There are several options available (in order of my preference):
- use a base controller to extend your controllers of, and do your global thing in that base controller (like load a 404 view)
- use a modular solution like Modular Extensions HMVC or Modular CI that solve this problem
- use a model/library to deal with your 404 (breaks MVC principles, but works without problems. be careful with output buffering when you exit)

or the dirty trick I used once:
- use the post_controller_constructor hook to check a switch (p.e. a session variable), then do
Code:
include APPPATH.'controllers/404controller.php';
$GLOBALS['CI'] = new 404controller();
$GLOBALS['class'] = '404controller';
$GLOBALS['method'] = 'show_404';
to tell the bootstrap to call your controller method instead of the one routed to when returning from the hook...

p.s. from a searchengine / SEO point of view, I would advise you to not hide the 404, but redirect to a 404 controller that displays a proper 404 page with the correct message, and instructions for your user. You don't want the googles of the world to block your site because valid url's sometimes return 404's instead of 200's...


Messages In This Thread
show_404 and 404_override - by El Forum - 03-28-2011, 06:57 AM
show_404 and 404_override - by El Forum - 04-05-2011, 11:53 AM
show_404 and 404_override - by El Forum - 04-05-2011, 03:00 PM
show_404 and 404_override - by El Forum - 04-05-2011, 04:15 PM
show_404 and 404_override - by El Forum - 04-05-2011, 04:58 PM
show_404 and 404_override - by El Forum - 06-07-2012, 03:35 PM
show_404 and 404_override - by El Forum - 09-22-2012, 10:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB