PHP code example of attogram / router
1. Go to this page and download the library: Download attogram/router 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/ */
attogram / router example snippets
use Attogram\Router\Router;
Allow routes
$router->allow('/', 'home');
$router->allow('/foo/bar', 'foobar');
$router->allow('/pi', 3.141);
$router->allow('/hello', function () { print 'world'; });
$router->allow('/book/?/chapter/?', function (Router $router) {
$book = $router->getVar(0);
$chapter = $router->getVar(1);
});
// Get the $control that matches the current request
$control = $router->match();
// If no match, $control is null
if (!$control) {
header('HTTP/1.0 404 Not Found');
exit;
}
// Now dispatch based on $control, in whatever manner you wish