PHP code example of gnatsnapper / altorouter-middleware
1. Go to this page and download the library: Download gnatsnapper/altorouter-middleware library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gnatsnapper / altorouter-middleware example snippets
$altorouter = new AltoRouterMiddleware();
//map array of routes
$altorouter->addRoutes(
[
[
'GET',
'/',
function () {
$r = new Response();
$r->getBody()->write('home');
return $r;
}
],
[
'GET',
'/users',
function () {
$r = new Response();
$r->getBody()->write('users');
return $r;
}
]
]
);
//or map single route
$altorouter->map(
'GET',
'/admin',
function () {
$r = new Response();
$r->getBody()->write('admin');
return $r;
}
);