--- title: Matching requests using AltoRouter layout: default ---

Using AltoRouter Matching Requests

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

{% highlight php startinline %} $match = $router->match(); {% endhighlight %}

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

{% highlight php startinline %} $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' } */ {% endhighlight %}

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 »