• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing the Whoops page

#1
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
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
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
(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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.