PHP code example of em4nl / urouter

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

    

em4nl / urouter example snippets




er = new Em4nl\U\Router();

// set a base path if this app doesn't live at the root path
// (right behind the domain)
$router->base('/my-app');

$router->get('/', function() {
    echo 'the index route';
});

$router->get('/test', function() {
    echo "the /test route";
});

$router->get('/:thing', function($thing) {
    echo "I like $thing!";
});

$router->get('/test/*', function($wildcard_match) {
    // will match paths of arbitrary length behind /test/ ...
});

$router->post('/form', function($context) {
    // ...
});

$router->catchall(function() {
    header('HTTP/1.1 404 Not Found');
    // ...
});

$router->run();