1. Go to this page and download the library: Download jblond/php-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/ */
jblond / php-router example snippets
new \jblond\Autoloader();
$router = new \jblond\router\Router();
$router->setBasepath('');
$router->init();
$router->add('/', function () {
echo 'Welcome';
});
$router->add('/info/', function () {
phpinfo();
});
$router->add('/test.html', function () {
echo 'test.html Welcome';
});
$router->add('/post/', function () {
$router->add('/user/(.*)/edit', function ($id) {
echo 'Edit user with id ' . $id;
});
$router->get('/test/(:any)', function () {
print_r(filter_input(INPUT_SERVER, 'REQUEST_URI'));
});
$tpl = new \Acme\Template\Template();
$router->add('/closure', function () use ($tpl) {
// $tpl->...
echo 'closure';
});