PHP code example of parable-php / routing

1. Go to this page and download the library: Download parable-php/routing 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/ */

    

parable-php / routing example snippets


$router = new Router();

$route1 = new Route(
    ['GET'],
    'simple-route',
    'route/simple',
    [Controller::class, 'actionName']
);

$route2 = new Route(
    ['GET', 'POST'],
    'param-route',
    'route/{param}/hello',
    function (string $param) {
        echo 'Hello, ' . $username . '!';
    }
);

$router->addRoutes($route1, $route2);

$match = $router->match('GET', 'route/devvoh/hello');

echo $match->getName();

$callable = $match->getCallable();
$callable(...$match->getParameterValues()->getAll());

$route = new Route(
    ['GET'],
    'simple-route',
    'route/simple',
    [Controller::class, 'actionName'],
    [
        'metadata' => 'enabled'
    ]
);

$route->getMetadataValue('metadata'); // returns 'enabled'
bash
$ composer