Welcome Guest, Not a member yet? Register   Sign In
changing the Whoops page
#1

(This post was last modified: 04-29-2020, 10:54 AM by George Rangel.)

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...
Reply
#2

(This post was last modified: 04-29-2020, 12:32 PM by Gary.)

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).
Reply
#3

(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.
Reply
#4

(This post was last modified: 04-29-2020, 12:42 PM by Gary.)

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.
Reply
#5

(This post was last modified: 04-29-2020, 12:48 PM by George Rangel.)

(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.
Reply
#6

(This post was last modified: 04-29-2020, 12:57 PM by Gary.)

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.
Reply
#7

yeahhh, worked! thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB