Altorouter

PHP5.3+ Routing Class. Supports REST, dynamic and reversed routing.

View the Project on GitHub dannyvankooten/AltoRouter

Download ZIP View on GitHub

Using AltoRouter Matching Requests

To match the current request, just call the `match()` method without any parameters.

$match = $router->match();

If a match was found, the match() method will return an associative array with the following 3 keys.

target (mixed)
The target of the route, given during mapping the route.

params (array)
Named parameters found in the request url.

name (string)
The name of the route.

Example

$router = new AltoRouter();
$router->map( 'GET', '/', function() { .. }, 'home' );

// assuming current request url = '/'
$match = $router->match();

/*
array(3) { 
	["target"]	=> object(Closure)#2 (0) { } 
	["params"]	=> array(0) { } 
	["name"] 	=> 'home' 
}
*/

AltoRouter does not process the request for you, you are free to use the method you prefer. Here is a simplified example how to process requests using closures though.

« Mapping routes Processing requests »