dougua3706 2015-09-11 01:09
浏览 13

Barebones PHP代码没有产生预期的结果

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端