1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-07-31 13:40:16 +02:00
Files
php-altorouter/usage/processing-requests.html
Danny van Kooten 6bd61a7a04 fix internal links
2023-10-09 20:14:26 +02:00

41 lines
1.1 KiB
HTML

---
title: Processing requests using AltoRouter
layout: default
---
<h1>
<small>Using AltoRouter</small>
Processing Requests
</h1>
<p>AltoRouter does not process requests for you so you are free to use the method you prefer. To help you get started, here's a simplified example using closures.</p>
{% highlight php startinline %}
$router = new AltoRouter();
// map homepage
$router->map( 'GET', '/', function() {
require __DIR__ . '/views/home.php';
});
// map user details page
$router->map( 'GET', '/user/[i:id]/', function( $id ) {
require __DIR__ . '/views/user-details.php';
});
// match current request url
$match = $router->match();
// call closure or throw 404 status
if( is_array($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');
}
{% endhighlight %}
<p>
<a style="float:left;" href="{{ '/usage/matching-requests.html' | relative_url }}">&laquo; Matching requests</a>
<br style="clear:both;">
</p>