PHP code example of flatpixels / light-route

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

    

flatpixels / light-route example snippets


$router = LightRoute\LightRouter::getInstance();

$router->addRoute('get', '/posts/', function(){
    echo "Welcome to the posts page";
});

$router->resolve();

$route->addRoute('get', 'post/:id', function($id) {
    echo "Show the post: " . $id;
});

$route->addRoute('get', 'post/:id/:slug/:author', function($id, $slug, $author) {
    echo "Show the post: " . $id;
    echo "With the slug: " . $slug;
    echo "Written by: " . $author;
});

$route->addRoute('get', 'post/:id', function($id) {
    echo "Show the post: " . $id;
})->format(['id' => "[0-9]"]);

$router->addRoute('get', '/go/to/single', function() use($router){

    //Redirect to the "single_post" route, with param: id=4
    $router->redirect('single_post', ['id' => 4]);
});