PHP code example of kyrill / php-route

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

    

kyrill / php-route example snippets





use Kyrill\PhpRoute\Router;
$router = new Router(); // add an instance of the Router

$router->resolveRoute();// resolves all the requests


$router->addRoute('GET', '/home', [Controller::class, 'home']);

$router->addRoute('GET','/routename', 'nameFunction')
});

public function nameFunction(){
    echo 'Hello function!';
}

$router->addRoute('GET','/anonymousfunction', function () {
    echo 'Hello anonymous function!';
});

$router->addRoute('GET','/user/{id}', [Controller::class, 'home']);

$router->addRoute('GET','/user/{id:[0-9]+}', [Controller::class, 'home']);

$router->addRoute('GET', '/home', [Controller::class, 'home'], [MiddlewareClass::class]);
bash
   composer