PHP code example of jadob / router

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

    

jadob / router example snippets


//Creating and configuring router instance:


//defining routes:
$routes = [
    'home' => [
        'path' => '/', //gnore_global_prefix' => true //if true, 
    ],
];


//if you need to add a set of routes with a common prefix:
$collection = new \Jadob\Router\RouteCollection();
$collection->setPrefix('/backend');


// this route will be matched on URI "/backend/posts/new"
$backendRoute = (new Route('backend_new_post'))
    ->setPath('/posts/new')
    ->setController(\Your\App\BackendController::class)
    ->setAction('newPost');



$collection->addRoute($backendRoute);

//when collection is passed to array, his key is ignored
$routes['backend_collection']  = $collection;


$routerConfig = [
    'routes' => $routes
];


$router = new \Jadob\Router\Router($routerConfig);