O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — handling 404 errors with Bones

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 the Bones class called resolve 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 called resolve outside the Bones class (such as get, post, put, or delete) 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required