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

[eluser]Glazz[/eluser]
Hello,

I'm using 404_override in my routes to show my custom error page, it works but only for non existing controllers, if you have a non existing method in a controller it shows the default error page.

Example:
Code:
http://domain.com/non-controller
This shows my custom error page.

Code:
http://domain.com/existing-controller/non-method
This shows the default CI error page.

Is this a bug? Or do i need to something else so it can show error for non existing methods inside existing controllers?


Regards
- Glazz
#2

[eluser]idealws[/eluser]
I am experiencing this same issue using CI 2.0.0 now. Anyone have a fix for this?

Regards,
Ray
#3

[eluser]Eric Barnes[/eluser]
I am testing this now and it is doing something weird. It is late here and I don't have time to fully test this to find a fix. Can you post this as a bug in the reactor?
https://bitbucket.org/ellislab/codeignit...status=new

Please be specific and thorough in the report.
#4

[eluser]Glazz[/eluser]
Eric,

https://bitbucket.org/ellislab/codeignit...de-problem

Don't know if i done it right though.

- G l a z z
#5

[eluser]Eric Barnes[/eluser]
Perfect! Wink
#6

[eluser]Eric Barnes[/eluser]
I just commited a fix for this:
https://bitbucket.org/ellislab/codeignit...a0e75a2101

Can you give that change a try and report back?
#7

[eluser]Glazz[/eluser]
Hello,

With those changes now whenever the method doesn't exist, it shows the index of the controller, it's better, but yet not as expected :c
#8

[eluser]Eric Barnes[/eluser]
Rats! I tested it but not thorough enough Sad I think this should do it if you want to test again.
Code:
// is_callable() returns TRUE on some versions of PHP 5 for private and protected
// methods, so we'll use this workaround for consistent behavior
if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
{
    // Check and see if we are using a 404 override and use it.
    if ( ! empty($RTR->routes['404_override']))
    {
        $x = explode('/', $RTR->routes['404_override']);
        $class = $x[0];
        $method = (isset($x[1]) ? $x[1] : 'index');

        if ( ! file_exists(APPPATH.'controllers/'.$class.EXT))
        {
            show_error('Unable to load your 404 controller. Please make sure the controller specified in your Routes.php file is valid.');
        }

        include(APPPATH.'controllers/'.$class.EXT);
        unset($CI);
        $CI = new $class();
    }
    else
    {
        show_404("{$class}/{$method}");
    }
}
#9

[eluser]Glazz[/eluser]
Yeaps, i believe it is working now, at least i've tested with some pages and it shows my custom error page x)

Thanks

- G l a z z


Edit:

Now i have another problem, if i try to access a non existing controller it shows the page fine, but for some reason if i try to access a non existing method it shows this:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$cart

Filename: views/topo.php

Line Number: 79

This is my custom error controller page:
Code:
<?php $this->load->view('topo'); ?>

<span class="separator"></span>

<div class="error404"><h2>404</h2>
    <h3>Looks like the page <br /> you're looking for isn't here anymore.<br /> Try using the search box or sitemap.</h3>
</div>

<span class="separator"></span>

&lt;?php $this->load->view('footer'); ?&gt;

If i comment out the load->view('topo'); line the error doesn't show up, but this only happens for non existing method's..
#10

[eluser]Eric Barnes[/eluser]
Giazz,

I just made another commit and in all my tests it is fully working. Can you give this a shot?
https://bitbucket.org/ellislab/codeignit...gniter.php




Theme © iAndrew 2016 - Forum software by © MyBB