You do not need to determine the route for this. F3 automatically generates a 404 status code for any undefined route.
If you want to define a custom error page, you need to set the ONERROR variable.
Here is an example:
$f3->route('GET /','App->home'); $f3->set('ONERROR',function($f3){ echo \Template::instance()->render('error.html'); }); $f3->run();
with error.html defined as:
<!DOCTYPE html> <head> <title>{{@ERROR.text}}</title> </head> <body> <h1>{{@ERROR.text}}</h1> <p>Error code: {{@ERROR.code}}</p> </body> </html>
Now, if you call any undefined route, for example / foo, the error.html template will be displayed 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 - any valid HTTP status code (404, 500, 403, etc.)
source share