Welcome Guest, Not a member yet? Register   Sign In
How to show 404 page in Codeigniter 4?
#1

Although it may seem trivial, I am having difficulty with a question. Previously in Codeigniter 3, I utilized the show_404() function in any controller to display a 404 page. How can I achieve the same outcome in Codeigniter 4?
Reply
#2

You can use the following command to display it.

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

But if you want to use show_404(), you can add the following code in file app/Common.php.

PHP Code:
<?php

use CodeIgniter\Exceptions\PageNotFoundException;

// Show 404 error

if (!function_exists('show_404')) {

    function show_404(string $error_text): string
    
{

        throw PageNotFoundException::forPageNotFound($error_text);

    }

Reply
#3

If you want to use CI3 features in CI4, you may find ci-3-to-4-upgrade-helper helpful.
For example, https://github.com/kenjis/ci3-to-4-upgra...on.php#L52
Reply




Theme © iAndrew 2016 - Forum software by © MyBB