PHP code example of penobit / irouter

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

    

penobit / irouter example snippets


$router = new iRouter();

// map homepage
$router->map('GET', '/', function() {
    

// Add multiple routes
$router->addRoutes(array(
  array('GET','/users/[i:id]', 'users#get', 'update_user'),
  array('PUT','/users/[i:id]', 'users#create', 'update_user'),
  array('PATCH','/users/[i:id]', 'users#update', 'update_user'),
  array('DELETE','/users/[i:id]', 'users#delete', 'delete_user')
));

// dynamic named route
$router->map('GET|POST', '/users/[i:id]/', function($id) {
  $user = .....
  

// echo URL to user-details page for ID 5
echo $router->generate('user-details', ['id' => 5]); // Output: "/users/5"

// Add match type
$router->addMatchTypes(array('customType' => '[a-zA-Z]{2}[0-9]?'));
$router->map('GET', '/use-match-type/[customType:paramName]', function() {