PHP code example of plugowski / php_router

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

    

plugowski / php_router example snippets



PhpRouter\Route;
use PhpRouter\RouteCollection;
use PhpRouter\Router;
use PhpRouter\RouteRequest;

$routing = new RouteCollection();
$routing->attach(new Route('GET /', function(){
    echo 'Hello World';
}));

(new Router(new RouteRequest(), $routing))->run();

new Route('GET /', '\Full\Namespace\Class->method');

new Route('GET /order/@id', '\Full\Namespace\Class->method');

// $_SERVER['REQUEST_URI'] = '/order/14-XA-43321'
new Route('GET /order/@id', ['id' => '\d{2}\-\w{2}\-\d{5}'], function($params) {
  echo 'Order ID: ' . $params['id']; // Order ID: 14-XA-43321 
});
bash
composer