PHP code example of carlosrivera / nano-router

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

    

carlosrivera / nano-router example snippets

 php
// Load and create the router
r = new Router();

// Add some routers, it support static and dynamic ones
$router->any('/', function() {
    echo "from index";
});

// For dynamic routes you can use regex or wildcards enclosed by <>
$router->get('/dynamic/<slug>/<id>', function($slug, $id) {
    echo "from dynamic with args: { slug: " . $slug . ", id: ". $id . "}";
});

// finally, just process the current route
$router->dispatch();
 php
$router->hooks->beforeRequest->add(function() {
	echo "before request firts hook \n";
});

$router->hooks->beforeRequest->add(function() {
	echo "before request second hook \n";
});

$router->hooks->afterRequest->add(function() {
	echo "after request hook \n";
});