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 — including the classes directory

In order for us to use our classes, we'll need to add some code to Bones so that we can automatically load class names as they are used. This will achieve that, so we don't have to continuously include more files as we add new classes.

Add the following code to lib/bones.php:

<?php
define('ROOT', __DIR__ . '/..');
require_once ROOT . '/lib/sag/src/Sag.php';
function __autoload($classname) {
include_once(ROOT . "/classes/" . strtolower($classname) . ".php");
}


What just happened?

We added a __autoload function to our Bones library that will give PHP a last attempt to load a class name if it can't find the class. The __autoload function is passed the $classname, and we use the $classname to find ...

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