PHP code example of mattvb91 / lightrouter

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

    

mattvb91 / lightrouter example snippets


$router = new mattvb91\LightRouter\Router();
$router->addRoute('/', MyController::class);
$router->run();

$router->addRoute('/', MyController::class);
$router->addRoute('/contact', MyController::class, 'contact');

$route->addRoute('/hello', function() {
    echo 'Hello world';
});

$router->addRoute('/view/:param', MyController::class);


public function view($param)
{
}

//Your route definition
$router->addRoute('/user/view/:user', UserController::class, 'view');

//In your UserController::class
public function view(User $user)
{
    //$user is already fully loaded for you.
}

public class CustomModel implements LightRouteModelInterface
{
    public static function getForLightRoute($routeParam): LightRouteModelInterface
    {
        //Use $routeParam to load your model class and return the instance
    }
}