Welcome Guest, Not a member yet? Register   Sign In
Problem with 404_override
#7

[eluser]SneakyDave[/eluser]
This 404 override is pretty worthless in my opinion. The problem is that some people may want to simply override the 404 processing by using the main controller of the web site.

This is pretty much worthless if you have any libraries auto loaded because the 404 override won't load any libraries, so the first time a library method is referenced, the user will see a PHP error, or a blank page, depending on the ENVIRONMENT.

The way I fixed it for a particular client that wanted the home page displayed for any "page not found" was to add some code in the index method of the default controller to check to see if the library object existed. If it didn't, that meant that the library wasn't auto-loaded, which means that came from a 404 error, so I force a redirect to default controller of the site, which would then function normally. A PITA, but you get what you pay for.

I don't use this anymore, because I think, it's sloppy, but there's got to be a better way. Forgive my use of the alternative IF/ENDIF syntax.

In the index method of the controller that is called by overriding the 404:
Code:
$this->_check_for_bad_object();

Code:
function _check_for_bad_object()
    {
        error_reporting(0);
        if(! is_object($this->the_library_that_should_be_autoloaded)):
            redirect('the real 404 redirect controller', 'refresh');
        endif;            
        switch (ENVIRONMENT)
        {
            case 'development':
                error_reporting(E_ALL);
            break;
    
            case 'testing':
            case 'production':
                error_reporting(0);
            break;
        }
}

You could probably use this for any 404 controller you wanted, as I think the only time a library file wouldn't be auto-loaded is a 404 condition, although you'd probably have to set your own header error value.


Messages In This Thread
Problem with 404_override - by El Forum - 06-09-2011, 11:53 AM
Problem with 404_override - by El Forum - 06-09-2011, 08:32 PM
Problem with 404_override - by El Forum - 06-09-2011, 09:43 PM
Problem with 404_override - by El Forum - 06-09-2011, 09:56 PM
Problem with 404_override - by El Forum - 06-09-2011, 10:04 PM
Problem with 404_override - by El Forum - 06-18-2011, 06:29 PM
Problem with 404_override - by El Forum - 06-23-2011, 07:04 PM
Problem with 404_override - by El Forum - 06-24-2011, 12:57 AM
Problem with 404_override - by El Forum - 06-24-2011, 01:35 AM
Problem with 404_override - by El Forum - 06-24-2011, 06:37 AM
Problem with 404_override - by El Forum - 06-24-2011, 06:52 AM
Problem with 404_override - by El Forum - 06-24-2011, 08:14 AM
Problem with 404_override - by El Forum - 06-24-2011, 08:27 AM
Problem with 404_override - by El Forum - 06-24-2011, 08:52 AM
Problem with 404_override - by El Forum - 06-24-2011, 09:06 AM
Problem with 404_override - by El Forum - 06-27-2011, 06:24 AM
Problem with 404_override - by El Forum - 07-18-2011, 01:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB