Skip to content

Configuration issue? #176

Closed
Closed
@brettalton

Description

@brettalton

I know this isn't a "I can't get this working" forum, but I've found it very difficult to get started with this project.

I have an index.php file inside demo-brett/listing with the following .htaccess

# from https://gist.github.com/chriso/874000

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

I'm using the single-file implementation to skip the autoloading headache like so,

/**
 * PHP Router called Klein (v2.0.2)
 *
 * Website:
 *      https://github.com/chriso/klein.php
 * Single file implmentation:
 *      https://raw2.github.com/gbouthenot/klein.php/K2-singlefile/src-single/klein.php
 * Readme:
 *      https://github.com/chriso/klein.php/blob/v2.0.2/README.md
*/
require_once('klein.php');

$klein = new \Klein\Klein();

But I can't seem to respond to absolutely anything, except for the generic "everything" response.

$klein->respond('/[:name]', function ($request) {
    return 'Hello ' . $request->name;
});

$klein->respond('GET', '/', function ($request) {
    return '[GET]';
});

$klein->respond('POST', '/', function ($request) {
    return '[POST]';
});

$klein->respond('GET', 'hello-world', function ($request) {
    return '[GET 1] Hello world';
});

$klein->respond('POST', 'hello-world', function ($request) {
    return '[POST 1] Hello world';
});

$klein->respond('GET', '/hello-world', function ($request) {
    return '[GET 2] Hello world';
});

$klein->respond('POST', '/hello-world', function ($request) {
    return '[POST 2] Hello world';
});

$klein->respond('/[:name]', function ($request) {
    return 'Hello ' . $request->name;
});

$klein->respond(function () {
    return 'All the things';
});

I'm then dispatching the response of course, but all I ever receive is All the things

/**
 * Generate response
 */
$klein->dispatch();

I have all the variables dumping at the bottom and nothing seems to be contained in $_GET or $_POST, only in $_SERVER

/**
 * Temporary profiling
 */
echo '<pre>';
var_dump($_GET);
var_dump($_POST);
var_dump($_SERVER);

If I visit http://localhost/demo-brett/listing/hello-world, I receive the following output,

array(0) {
}
array(0) {
}
array(31) {
  ["REDIRECT_STATUS"]=>
  string(3) "200"
  ["HTTP_HOST"]=>
  string(24) "localhost"
  ["HTTP_CONNECTION"]=>
  string(10) "keep-alive"
  ["HTTP_CACHE_CONTROL"]=>
  string(9) "max-age=0"
  ["HTTP_ACCEPT"]=>
  string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  ["HTTP_USER_AGENT"]=>
  string(119) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"
  ["HTTP_DNT"]=>
  string(1) "1"
  ["HTTP_ACCEPT_ENCODING"]=>
  string(17) "gzip,deflate,sdch"
  ["HTTP_ACCEPT_LANGUAGE"]=>
  string(26) "en-CA,en;q=0.8,en-US;q=0.6"
  ["SERVER_NAME"]=>
  string(24) "localhost"
  ["SERVER_ADDR"]=>
  string(13) "127.0.0.1"
  ["SERVER_PORT"]=>
  string(2) "80"
  ["REMOTE_ADDR"]=>
  string(11) "127.0.0.1"
  ["DOCUMENT_ROOT"]=>
  string(51) "/Users/brett/www/"
  ["SERVER_ADMIN"]=>
  string(14) "root@localhost"
  ["SCRIPT_FILENAME"]=>
  string(79) "/Users/brett/www/demo_brett/listing/index.php"
  ["REMOTE_PORT"]=>
  string(5) "63737"
  ["REDIRECT_URL"]=>
  string(31) "/demo_brett/listing/hello-world"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["QUERY_STRING"]=>
  string(0) ""
  ["REQUEST_URI"]=>
  string(31) "/demo_brett/listing/hello-world"
  ["SCRIPT_NAME"]=>
  string(29) "/demo_brett/listing/index.php"
  ["PHP_SELF"]=>
  string(29) "/demo_brett/listing/index.php"
  ["REQUEST_TIME"]=>
  int(1390244324)
}

Does anyone know what may be occurring?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions