1. Go to this page and download the library: Download kunststube/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/ */
$r = new Router;
// matches GET, POST, PUT and DELETE requests
$r->add('/foo');
// matches only GET requests
$r->addGet('/bar');
// matches the same URL as above, but only for POST requests
$r->addPost('/bar');
// matches PUT and POST requests
$r->addMethod($r::PUT | $r::POST, '/baz');
// custom route matching only HEAD requests
$r->addMethodRoute($r::HEAD, new CaseInsensitiveRoute('/42'));
new Kunststube\Router\Router;
$r->add('/foo');
...
$r->route($_GET['url']);
$r = new Kunststube\Router\Router;
switch ($_SERVER['HTTP_HOST']) {
case 'example.com' :
$r->add('/foo');
...
break;
case 'elpmaxe.moc' :
$r->add('/bar');
...
break;
}
$r->route($_GET['url']);
$r = new Kunststube\Router\Router;
$r->add('/foo', array(), function (Route $route) use ($r) {
$controller = new MyController;
$controller->run($r);
});
$r = new Router(new CaseInsensitiveRouteFactory);
$r = new Router;
$r->add('/regular/case/sensitive/route');
$caseInsensitiveRoute = new CaseInsensitiveRoute('/case/insensitive/route');
$r->addRoute($caseInsensitiveRoute, function () {
echo 'This will match';
});
$r->route('/Case/INSENSITIVE/rOuTe');
function (Route $route) {
echo $route->controller;
echo $route->action;
}
$r = new Route('/foo/\d+:id');
$r->id = 'bar'; // invalid value for pattern \d+
$r = new Router;
$r->add('/item/\d+:id', array(), function (Route $route) {
echo "Now visiting item {$route->id}. ";
$route->id = $route->id + 1;
echo "The next item is at " . $route->url();
});
$r->route('/item/42'); // Now visiting item 42. The next item is at /item/43
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.