[英]Codeigniter 4 - how to show 404 page?
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.这是一个非常愚蠢的问题,但我无法处理:) 在 Codeigniter 3 中,我只是在任何 Z594C103F2C6E04C3D8AB059F031E0 页面中使用了 show_404() function。 How could I do the same with Codeigniter 4?
我怎么能对 Codeigniter 4 做同样的事情?
I was looking just now exactly for the same thing.我刚才正在寻找完全相同的东西。 I found here the solution: CodeIgniter 4 User Guide - Error Handling
我在这里找到了解决方案: CodeIgniter 4 用户指南 - 错误处理
In your controller, simply write:在您的 controller 中,只需编写:
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
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 https://codeigniter4.github.io/userguide/incoming/routing.html#override
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.