Let's add some simple code around lib/bones.php
and index.php
that will allow us to handle 404
errors.
1. Open
lib/bones.php
, and a create a function inside theBones
class calledresolve
that we can call at the end of our routes and determine if a route was ever found.public static function resolve() { if (!static::$route_found) { $bones = static::get_instance(); $bones->error404(); } }
2. Go to the top of
lib/bones.php
, and create a function calledresolve
outside theBones
class (such asget, post, put
, ordelete)
that we can call outside anywhere.function resolve() { Bones::resolve(); }
3. All that's left for us to do is add a line of code at the very bottom of
index.php
that can be called if no routes are found. As you add more routes, make sure thatresolve()
is always at the end of the file.get('/user/:username', function($app) { $app->set('user', User::get_by_username($app- >request('username'))); $app->render('user/profile...