mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-10-23 12:16:16 +02:00
Add usage pages.
This commit is contained in:
40
usage/processing-requests.html
Normal file
40
usage/processing-requests.html
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
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( $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">« Matching requests</a>
|
||||
<br style="clear:both;">
|
||||
</p>
|
Reference in New Issue
Block a user