0

We have introduced the Twig template engine to CodeIgniter 4.
The template folder has been changed directly under the project folder(/templates).
The 404 error page has been replaced.

$routes->set404Override('App\Controllers\Template::notFound')

App\Controllers\Template

//...

class Template extends BaseController
{
  // ...
  public function notFound ()
  {
      return $this->twig->display('errors/custom404'); // <- /templates/errors/custom404.twig
  }

And in production, other errors are reading the production.php file (/app/Views/errors/html/production.php).
I also want to overwrite the exception handling page, what should I do?

Specifically, I want to load the production.twig file (/templates/errors/production.twig) instead of the production.php file (/app/Views/errors/html/production.php).

Is there a way to override the exception page like a 404 page controller?


vendor/codeigniter4/framework/system/Debug/Exceptions.php

I can see that production.php is hardcoded in the method determineView, is it possible to override this method?
And is it okay to overwrite?

Devatim
  • 331
  • 2
  • 10
  • Which version of CI is this? You have CI, CI2, CI3 all tagged. I'm assuming that it is the latest version. See the documentation here: https://codeigniter.com/user_guide/general/errors.html – CGSmith105 Jul 07 '20 at 02:03
  • Does this answer your question? https://stackoverflow.com/a/61631214/11581254 – Monayem Islam Jul 07 '20 at 02:09
  • The 404 page has already been overwritten. I don't know how to override the view(replace with Twig template) for other exceptions such as 500. – Devatim Jul 07 '20 at 02:40
  • `vendor/codeigniter4/framework/system/Debug/Exceptions.php` I can see that production.php is hardcoded in the method `determineView`, is it possible to override this method? – Devatim Jul 07 '20 at 02:51

0 Answers0