Home » Php » php – Fat Free Framework (F3): custom 404 page (and others errors)

php – Fat Free Framework (F3): custom 404 page (and others errors)

Posted by: admin July 12, 2020 Leave a comment


How I can handle my 404 custom page (and possibly other errors)?

I just tried in routing part to add

GET /@codes /WebController->error

Where my Class WebController handles error, and for 404 i solved (partially). In effect it works for


but if i recall a


My route (of course) doesn’t work.

Btw, with that route in every case it doesn’t push 404 header (just a maniac-vision of things, i’m thinking to Google looking for a resources and it doesn’t receive a “pure” 404).

Thank you

How to&Answers:

You don’t have to define a route for this. F3 will automatically generate a 404 status code for any non-defined route.

If you want to define a custom error page, you need to set the ONERROR variable.

Here’s a quick example:

$f3->route('GET /','App->home');
  echo \Template::instance()->render('error.html');

with error.html defined as:

<!DOCTYPE html>
  <p>Error code: {{@ERROR.code}}</p>

Now if you call any non-defined route like /foo, the template error.html will be rendered with a 404 status code.

NB: this works for other error codes. Other error codes are triggered by F3 or your application with the command $f3->error($status), $status being any valid HTTP status code (404, 500, 403, etc…)