Php Codeigniter 4-如何显示404页面?

Php Codeigniter 4-如何显示404页面?,php,codeigniter,Php,Codeigniter,这是一个非常愚蠢的问题,但我无法处理:)在Codeigniter 3中,我只是在任何控制器中使用show_404()函数来显示404页面。如何使用Codeigniter 4实现同样的效果?你可以试试这个 <?php // Would execute the show404 method of the App\Errors class $routes->set404Override('App\Errors::show404'); // Will displ

这是一个非常愚蠢的问题,但我无法处理:)在Codeigniter 3中,我只是在任何控制器中使用show_404()函数来显示404页面。如何使用Codeigniter 4实现同样的效果?

你可以试试这个

    <?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');
    });

我刚才也在找同样的东西。
我在这里找到了解决方案:

在控制器中,只需写下:

throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();