The following bones.php and index.php (taken from Juravich, CouchDB and PHP Web Development) should produce the following results from my browser:
If I enter http://localhost/verge/, then I should see the word Home.
If I enter http://localhost/verge/signup/,then I should see the word Signup.
Instead, I get blank pages. I've checked for typos since this was copied directly out of the book. But being a newbie at PHP, I don't know if the error is the author's, or more likely, mine.
Here's the code for index.php:
<?php
include 'lib/bones.php';
get('/', function($app) {
echo "Home";
});
get('/signup', function($app) {
echo "Signup";
});
And here's bones.php:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ERROR | E_PARSE);
function get($route, $callback) {
Bones::register($route, $callback);
}
class Bones {
private static $instance;
public static $route_found = false;
public $route = '';
public function _contruct() {
$this->route = $this->get_route();
}
public static function get_instance() {
if (!isset(self::$instance)) {
self::$instance = new Bones();
}
return self::$instance;
}
public static function register($route, $callback) {
$bones = static::get_instance();
if ($route == $bones->route && !static::$route_found) {
static::$route_found = true;
echo $callback($bones);
} else {
return false;
}
}
protected function get_route() {
parse_str($_SERVER['QUERY_STRING'], $route);
if ($route) {
return '/' . $route ['request'];
} else {
return '/';
}
}
}
Please understand. I do not want to make major modifications in the author's code. This is only chapter 4 of 10, and I want to follow along and understand.
Thank you.