dannyvankooten / AltoRouter

PHP routing class. Lightweight yet flexible. Supports REST, dynamic and reversed routing.
https://dannyvankooten.github.io/AltoRouter/
MIT License
1.22k stars 230 forks source link

Nothing happens #182

Closed Bram-Zijp closed 7 years ago

Bram-Zijp commented 7 years ago

Tried installing with composer and manually running locally with WAMP php 5.6.x but can't get any of the routes to fire. Tried mapping with vhosts and such but no response is ever made.

require 'AltoRouter.php';
$router = new AltoRouter();
$router->map( 'GET', '/', function() {
    echo 'lol';
});
manishbathla commented 7 years ago

you forgot to add

// match
$match = $router->match();

// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] ); 
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}

plus, if your project lives in a sub-folder of your web root you use the setBasePath() method to set a base path. $router->setBasePath('/foldername');

koenpunt commented 7 years ago

Closing because of no response of OP