6

It's a very silly question but I can't handle it :) In Codeigniter 3, I just used show_404() function in any controller to show 404 page. How could I do the same with Codeigniter 4?

Anton
  • 73
  • 1
  • 1
  • 6

2 Answers2

14

I was looking just now exactly for the same thing. I found here the solution: CodeIgniter 4 User Guide - Error Handling

In your controller, simply write:

throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
deste
  • 542
  • 1
  • 5
  • 17
2

U can try this

    <?php
  // Would execute the show404 method of the App\Errors class
    $routes->set404Override('App\Errors::show404');

    // Will display a custom view
    $routes->set404Override(function()
    {
        echo view('my_errors/not_found.html');
    });

https://codeigniter4.github.io/userguide/incoming/routing.html#override

demenvil
  • 1,089
  • 1
  • 12
  • 25