codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.31k stars 1.89k forks source link

Bug: 404 error page override with cache #2391

Closed crustamet closed 4 years ago

crustamet commented 4 years ago

TypeError Argument 1 passed to CodeIgniter\CodeIgniter::cachePage() must be an instance of Config\Cache, null given, called in /projects/ci4/system/CodeIgniter.php on line 960

dafriend commented 4 years ago

It would be helpful to know exactly which version of CI4 you are using. I cannot find a commit where that function is on line 960, so my first suggestion is making sure you are using a current release.

It would also be helpful to see the code you are executing that leads to error.

crustamet commented 4 years ago

It is the latest update please search for this function cachePage in system/Codeigniter.php line : 959 where it is get called. and 615 where the method is defined.

crustamet commented 4 years ago

This file here my brother. https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/CodeIgniter.php

crustamet commented 4 years ago

I overrided the Error Page and cache the error page.

That is it.

crustamet commented 4 years ago

You understand or i need a more exemplified with code to show.. I think it is very straight forward.

Override the Error from the config with your controller. and inside that Error default function you simply just put $this->cachePage(60);

You will get the error i posted up top.

dafriend commented 4 years ago

The call $this->cachePage(60) is made from a controller?

crustamet commented 4 years ago

Yes.. and From the Error override controller.

dafriend commented 4 years ago

@crustamet, Please confirm. You did something like this?

$routes->set404Override('App\Errors::show404');

I would really like to see the code

From the Error override controller.

crustamet commented 4 years ago

Yes wait i was testing some stuff but i know for sure what is the problem..

So i have this setup

$routes->set404Override('App\Controllers\Errors::showErrorPage');

With this Controller

class Errors extends Controller
{
    public function showErrorPage()
    {
        $this->cachePage(360);

        $this->ViewData['LayoutView'] = 'Frontpanel/Errors/Errors';

        echo view('master', $this->ViewData);
    }
}

if i remove $this->cachePage(360); the error does not show

dafriend commented 4 years ago

Thanks. I am able to reproduce the problem. Now to figure out why.