Welcome Guest, Not a member yet? Register   Sign In
How to create custom Error 404 page
#1

Hello, guys!

I'm creating a RESTful resource and I marked the page "new" as except.

OK. Everything working nice, BUT, how to handle a custom Error 404 page in JSON format (the default is html) when someone access the /new path?
Reply
#2

(This post was last modified: 02-02-2020, 05:30 PM by littlej.)

Hello Falko !

You can set a custom 404 page in the "app/Config/Routes.php" file: https://codeigniter4.github.io/userguide...l#override

The part that will interest you is:
PHP Code:
// Would execute the show404 method of the App\Errors class
$routes->set404Override('App\Errors::show404'); 

So you just have to redirect to a Class::method of your choice, that will return the json response you are looking for :-)


> Maybe the RESTful madman will have something to add ? :-D
Reply
#3

(02-02-2020, 05:24 PM)littlej Wrote: Hello Falko !

You can set a custom 404 page in the "app/Config/Routes.php" file: https://codeigniter4.github.io/userguide...l#override

The part that will interest you is:
PHP Code:
// Would execute the show404 method of the App\Errors class
$routes->set404Override('App\Errors::show404'); 

So you just have to redirect to a Class::method of your choice, that will return the json response you are looking for :-)


> Maybe the RESTful madman will have something to add ? :-D

Thank you! It solved my question.
Reply
#4

Perfect ! :-) If you have time, don't forget to rate my answer with the "Rate" button at the bottom ;-)
Reply
#5

(02-19-2020, 01:27 PM)littlej Wrote: Perfect ! :-) If you have time, don't forget to rate my answer with the "Rate" button at the bottom ;-)

The button is not working. It just freeze the screen.
Reply
#6

No problem. The most important thing is that you have got a solution ;-)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB