Part of the EllisLab Network
   
2 of 3
2
404_override doesn’t work as expected..
Posted: 03 February 2011 05:37 AM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  1
Joined  02-03-2011
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.

Profile
 
 
Posted: 08 February 2011 03:16 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  168
Joined  12-12-2010

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

Profile
 
 
Posted: 12 February 2011 12:21 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Rank
Total Posts:  34
Joined  07-10-2009

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

Profile
 
 
Posted: 17 February 2011 12:48 PM   [ Ignore ]   [ # 19 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  185
Joined  07-10-2010

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

Profile
 
 
Posted: 17 February 2011 04:08 PM   [ Ignore ]   [ # 20 ]  
Grad Student
Rank
Total Posts:  34
Joined  07-10-2009

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

Profile
 
 
Posted: 17 February 2011 04:30 PM   [ Ignore ]   [ # 21 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  185
Joined  07-10-2010

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

Profile
 
 
Posted: 17 February 2011 04:38 PM   [ Ignore ]   [ # 22 ]  
Grad Student
Rank
Total Posts:  34
Joined  07-10-2009

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

Profile
 
 
Posted: 20 February 2011 04:31 AM   [ Ignore ]   [ # 23 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  474
Joined  01-30-2011

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.

Profile
 
 
Posted: 25 February 2011 02:13 PM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  190
Joined  12-23-2008

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

Profile
 
 
Posted: 25 February 2011 03:57 PM   [ Ignore ]   [ # 25 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  474
Joined  01-30-2011

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.

Profile
 
 
Posted: 25 February 2011 05:21 PM   [ Ignore ]   [ # 26 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  190
Joined  12-23-2008

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

Profile
 
 
Posted: 25 February 2011 05:30 PM   [ Ignore ]   [ # 27 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  474
Joined  01-30-2011

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.

Profile
 
 
Posted: 25 February 2011 07:52 PM   [ Ignore ]   [ # 28 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3216
Joined  06-10-2007

@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

Profile
 
 
Posted: 25 February 2011 09:45 PM   [ Ignore ]   [ # 29 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  190
Joined  12-23-2008
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?

Profile
 
 
Posted: 11 April 2011 01:44 PM   [ Ignore ]   [ # 30 ]  
Grad Student
Avatar
Rank
Total Posts:  55
Joined  07-31-2010

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

Profile
 
 
   
2 of 3
2