CodeIgniter Forums
changing the Whoops page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: changing the Whoops page (/thread-76278.html)



changing the Whoops page - George Rangel - 04-29-2020

Hello!

How can I change the Whoops page (App/Views/errors/html/production.php), of couse in CI_ENVIRONMENT = production, like we can do for 404 pages?

In 404 pages I have already done, changing the Routers.php:
PHP Code:
$routes->set404Override('App\Controllers\Errors::index'); 

... but for Whoops page I did not find how to do it in CI4 Manual.

I was thinking to make a page redirect in production.php, but I think is not the right way...


RE: changing the Whoops page - Gary - 04-29-2020

There are a couple of ways, probably the easiest is to simply edit/replace the \app\Views\errors\html\production.php file without changing anything else (not far off your suggestion of having a redirection in there).

Another way to do it without messing around in the framework code is to intercept the response with an after filter (though, be aware that this won't work in any other ENVIRONMENT than production, because the exception thrown in the framework under develeopment (and I suspect under testing too) terminates in the exception code (which stops the after filter from ever being activated).


RE: changing the Whoops page - George Rangel - 04-29-2020

(04-29-2020, 12:22 PM)Gary Wrote: There are a couple of ways, probably the easiest is to simply edit/replace the \app\Views\errors\html\production.php file.

Thanks for response. But I want to send the request to a specific Controller. Not just change the HTML.


RE: changing the Whoops page - Gary - 04-29-2020

After my experimentation, I ended up redirecting to a controller in production.php as you suggested... there may be a better way, but I found most of the others started becoming messy.

After filters can also be a bit limited and difficult to do efficiently (particularly if the site is mixed with JavaScript responses)- one has to swap out the body on an outgoing messge... and one doesn't want too much unnecessary processing stuck in there, as it'll be run on ever response.

Let us know if you find a better way.


RE: changing the Whoops page - George Rangel - 04-29-2020

(04-29-2020, 12:41 PM)Gary Wrote: After my experimentation, I ended up redirecting to a controller in production.php as you suggested... there may be a better way, but I found most of the others started becoming messy.

After filters can also be a bit limited and difficult to do efficiently (particularly if the site is mixed with JavaScript responses)- one has to swap out the body on an outgoing messge... and one doesn't want too much unnecessary processing stuck in there, as it'll be run on ever response.

Let us know if you find a better way.
 
Yes, I did the redirecting. But in this way, the user can see the page being reloading.

If the CI catch the error and redirect to production.php, must be a way.

Thanks for while.


RE: changing the Whoops page - Gary - 04-29-2020

It can be done very easily without a reload, if one redirects the PROCESSING to a controller (and not the user's browser)... like this (this is the only code in my production.php):

Code:
<?php
    $error = new \App\Controllers\Error();
    return $error->error(array('error_type' => '500'));
?>

\App\Controllers\Error is my custom controller that handles all the exceptions, and error() is obviously a custom function which takes an array as a parameter.


RE: changing the Whoops page - George Rangel - 04-29-2020

yeahhh, worked! thanks.