PHP code example of boxunphp / router

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

    

boxunphp / router example snippets


$config = [
    ['method' => 'GET', 'route' => '/aaa[/{id:number}/{age}/ggg[/bbb[/ccc[/ddd]]]]', 'handler' => 'handlerA'],
    ['group' => '/bbb', 'routes' => [
        ['method' => 'GET', 'route' => '/uuu[/{id:number}/{age}/ggg[/bbb[/ccc[/ddd]]]]', 'handler' => 'handlerBU'],
        ['method' => 'GET', 'route' => '/iii[/{id:number}/{age}/ggg[/bbb[/ccc[/ddd]]]]', 'handler' => 'handlerBI'],
        ['method' => 'GET', 'route' => '/ooo[/{id:number}/{age}/ggg[/bbb[/ccc[/ddd]]]]', 'handler' => 'handlerBO'],
    ]],
    ['method' => 'GET', 'route' => '/ccc[/{id:number}]', 'handler' => 'handlerC'],
]; 
$router = new Router($config);
$uri = '/aaa/10000/18/ggg?a=AAA&b=BBB';
$router->dispatch($method, $uri);