PHP code example of uk / routing

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

    

uk / routing example snippets


// Include the autoloader, created by composer
ype;

// Init the router
$router = new Router(
   // The type of the router
   RouterType::REWRITE_TO_REQUEST_URI
);

// Adds an dynamic regex URI path route
$router->addRoute(
   '~^/foo/(\d+)/bar/?$~',
   function ( array $matches )
   {
      // If you need access to current Router instance can get it by Router::GetInstance()
      echo 'ID: ', $matches[ 1 ], ' OK :-)';
      exit;
   }
);

// Adds an static URI path route
$router->addRoute(
   '~^/baz/?$~',
   function ()
   {
      // If you need access to current Router instance can get it by Router::GetInstance()
      echo 'The BAZ is called!';
      exit;
   }
);


if ( ! $router->execute() )
{
   // Showing 404 error because no router matches the defined request URI path.
}

try_files $uri $uri/ /index.php?$args;