404 and page_router

edited June 2012 in Bug Reports
Ok here's a tricky one:

1) I'd like to be able to reroute ALL not-found URLs to the 'home' controller instead of showing a 404 page. Is this possible / the right thing to do? I've tried setting the $route['404_ovveride'] = 'home'; but that just throws a lot of errors:

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 1

Filename: fuel/Router.php

Line Number: 93

A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/[REDACTED]/fuel/codeigniter/core/Exceptions.php:170)

Filename: core/Common.php

Line Number: 414

An Error Was Encountered
Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.
so i've reset it back to 'fuel/page_router'.

2) A major issue is that if you actually hit an existing controller but an non-existing method, a really ugly error page is shown instead of the 404:

A PHP Error was encountered
Severity: Notice

Message: Undefined offset: 1

Filename: hooks/Fuel_hooks.php

Line Number: 48

A PHP Error was encountered
Severity: Warning

Message: require_once(/Applications/MAMP/htdocs/[REDACTED]/fuel/application/../modules/fuel//controllers/.php) [function.require-once]: failed to open stream: No such file or directory

Filename: hooks/Fuel_hooks.php

Line Number: 48
How can I change that?? Please help, this is really important!!!

Comments

  • edited 9:54AM
    What if you just add the following to your error_404 page:
    header('Location: /home'); exit();
  • edited 9:54AM
    that might do the trick for case 1, but what about case 2?
  • edited 9:54AM
    The issue for number 2 has been fixed in the next release. The fix is the following in that file:
    function pre_controller() { // if called from same Wordpress, the the global scope will not work global $method, $class, $RTR; $class_methods = get_class_methods($class); // for pages without methods defined if ((isset($class_methods) AND !in_array($method, $class_methods) AND !in_array('_remap', $class_methods)) AND !empty($RTR->default_controller)) { $fuel_path = explode('/', $RTR->routes['404_override']); if (!empty($fuel_path[1])) { require_once(FUEL_PATH.'/controllers/'.$fuel_path[1].'.php'); $class = $fuel_path[1]; } } }
Sign In or Register to comment.