Welcome Guest, Not a member yet? Register   Sign In
404_override doesn't work as expected..
#21

[eluser]thePiet[/eluser]
I've fixed it, in a nasty way. I had to change three lines of code in the system/ folder.

Create application/core/MY_Loader.php:

Code:
class MY_Loader extends CI_Loader {

    function __construct()
    {
        parent::__construct();
    }

    function reset()
    {
        $this->_ci_cached_vars = array();
        $this->_ci_classes = array();
        $this->_ci_loaded_files = array();
        $this->_ci_models = array();
        $this->_ci_helpers = array();
    }
}

Replace "include_once()" with "include()" in system/core/Loader.php:

Code:
function _ci_autoloader()
    {
        include(APPPATH.'config/autoload'.EXT);

        if ( ! isset($autoload))
        {
            return FALSE;
        }

Add two lines in system/core/CodeIgniter.php ($CI->load->reset(); and $CI->load->_ci_autoloader()Wink:

Code:
if ( ! file_exists(APPPATH.'controllers/'.$class.EXT))
                    {
                        show_404("{$class}/{$method}");
                    }

                    include_once(APPPATH.'controllers/'.$class.EXT);
                    unset($CI);
                    $CI = new $class();

                    $CI->load->reset();
                    $CI->load->_ci_autoloader();
                }
            }

And it's working.
#22

[eluser]victorche[/eluser]
Yes, the solution is working... But i still think this is a bug
#23

[eluser]thePiet[/eluser]
Yeah, the problem is that the loader class (obviously) ignores loading classes twice, and the include_once() in system/core/Loader.php prevents the autoload array from being loaded a second time.

If somebody has a more decent solution, shoot! Or some CI / Reactor dev: commit this stuff to the repo (and adopt the loader->reset() method in the core).
#24

[eluser]Basketcasesoftware[/eluser]
Hmm. I've been doing a little work on the CI_Loader class myself and someone has already asked me to create a Reactor fork (done, just have to incorporate my work yet). I've strictly been focused on the library loader method, but I'm marking this thread. I'll try playing with your solution some. You are calling a Loader method directly that's supposed to be a private function to the class, but that's a known holdover from CI < 2.0
I don't see anything wrong right now with the change from include_once to include but there might be a better way.
#25

[eluser]bubbafoley[/eluser]
using thePiet's idea of adding a reset() function to the loader I've come up with this solution that fixes all the 404 override problems and allows to override the error page for any status code. I've put in a pull request so hopefully this will be fixed in the next release.

https://bitbucket.org/bubbafoley/codeign...320ae89bbf
#26

[eluser]Basketcasesoftware[/eluser]
Your 404-error pull request link is... a 404 Error! :cheese: You might want to fix that.
#27

[eluser]bubbafoley[/eluser]
is fixed. somehow an extra 's' got added to the end of the link
#28

[eluser]Basketcasesoftware[/eluser]
Don't feel bad. I had a link a couple of days ago to my OWN site that I forgot the '.com'
#29

[eluser]wiredesignz[/eluser]
@bubbafoley, Nice effort, using the status override variable in routes is a nice idea too. But you should not load a controller from the exceptions class. There should be only one point in the core where controllers are loaded.
#30

[eluser]bubbafoley[/eluser]
[quote author="wiredesignz" date="1298699573"]@bubbafoley, Nice effort, using the status override variable in routes is a nice idea too. But you should not load a controller from the exceptions class. There should be only one point in the core where controllers are loaded.[/quote]

yeah I didn't like doing it that way but it was the only way I could find that a) didn't have duplicate code all over the place, and b) worked in all cases.

For instance, the current broken implementation checks the 404 override in _validate_request() in system/core/Router.php before calling show_404() then does the same check in system/core/CodeIgniter.php if a controller function doesn't exist. It doesn't work for missing controllers in subdirectories or when uncallable functions are passed through the URL.

The simple fix then is that the same check needs to be applied everywhere show_404() is called in the boot process. That's alot of redundant code. But it's still broken because if you call show_404() from a controller, the override won't take because show_error() doesn't check for it.

Is there a better way to call the controller?




Theme © iAndrew 2016 - Forum software by © MyBB