EllisLab text mark
Advanced Search
2 of 3
2
   
404_override doesn’t work as expected..
Posted: 03 February 2011 05:37 AM   [ # 16 ]   [ Rating: 0 ]
Joined: 2011-02-03
1 posts
http://domain.com/existing-directory/non-controller 

or

http://domain.com/existing-directory/existing-directory/non-controller 

etc…

It shows default CI error page too.

 
Posted: 08 February 2011 03:16 PM   [ # 17 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-12
192 posts

Hello,

I’ve been testing, and this error happens with most of the libraries.

I tried to fix it but i didn’t have success with it :c

 
Posted: 12 February 2011 12:21 PM   [ # 18 ]   [ Rating: 0 ]
Joined: 2009-07-10
32 posts

I’m suffering the same issue here.

application/routes.php:

$route['404_override''error/not_found'

application/controllers/error.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Error extends CI_Controller {

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

    
*snip*

    function 
not_found()
    
{
        $this
->breadcrumb->append('Pagina niet gevonden');

        
$this->load->view('header');
        
$this->load->view('error/not_found');
        
$this->load->view('footer');
    
}

As you can see I’m using a breadcrumb class to handle breadcrumbs. But this happens when throwing the 404 error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Error::$breadcrumb
Filename: controllers/error.php
Line Number: 30

Fatal error: Call to a member function append() on a non-object in application/controllers/error.php on line 30

So it looks like libraries that are auto-loaded, aren’t loaded anymore or something. Manually loading the libraries in the controller doesn’t affect the error.

In short, it isn’t possible to use other libraries / helpers / plugins within the 404_override route.

 Signature 

cool smile

 
Posted: 17 February 2011 12:48 PM   [ # 19 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-10
183 posts

for some reason, the autoloaded libraries are not loaded :/
i have the same problem too…

 
Posted: 17 February 2011 04:08 PM   [ # 20 ]   [ Rating: 0 ]
Joined: 2009-07-10
32 posts

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:

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:

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();):

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.

 Signature 

cool smile

 
Posted: 17 February 2011 04:30 PM   [ # 21 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-10
183 posts

Yes, the solution is working… But i still think this is a bug

 
Posted: 17 February 2011 04:38 PM   [ # 22 ]   [ Rating: 0 ]
Joined: 2009-07-10
32 posts

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).

 Signature 

cool smile

 
Posted: 20 February 2011 04:31 AM   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-30
454 posts

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.

 Signature 

This is the wonderful logo InsiteFX did for me. I had to scale it for this site. But his work is worth showing off.

 
Posted: 25 February 2011 02:13 PM   [ # 24 ]   [ Rating: 0 ]
Avatar
Joined: 2008-12-23
189 posts

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/codeigniter-error-overrides/changeset/36320ae89bbf

 
Posted: 25 February 2011 03:57 PM   [ # 25 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-30
454 posts

Your 404-error pull request link is… a 404 Error! cheese You might want to fix that.

 Signature 

This is the wonderful logo InsiteFX did for me. I had to scale it for this site. But his work is worth showing off.

 
Posted: 25 February 2011 05:21 PM   [ # 26 ]   [ Rating: 0 ]
Avatar
Joined: 2008-12-23
189 posts

is fixed. somehow an extra ‘s’ got added to the end of the link

 
Posted: 25 February 2011 05:30 PM   [ # 27 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-30
454 posts

Don’t feel bad. I had a link a couple of days ago to my OWN site that I forgot the ‘.com’

 Signature 

This is the wonderful logo InsiteFX did for me. I had to scale it for this site. But his work is worth showing off.

 
Posted: 25 February 2011 07:52 PM   [ # 28 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 posts

@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.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 25 February 2011 09:45 PM   [ # 29 ]   [ Rating: 0 ]
Avatar
Joined: 2008-12-23
189 posts
wiredesignz - 26 February 2011 12:52 AM

@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.

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?

 
Posted: 11 April 2011 02:44 PM   [ # 30 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-31
54 posts

Does anyone got a fix for this? My classses aren’t loaded on the 404 page…

 Signature 

William Rufino is a Web Developer from Brazil and writes a blog a about codeigniter and web development on www.williamrufino.com.br/blog/ (in portuguese)

Owner of Hollo Interact

 
2 of 3
2