1. Go to this page and download the library: Download sodaho/php-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/ */
sodaho / php-router example snippets
// public/index.php
Sodaho\Router\Router::create()->loadRoutes(__DIR__ . '/../routes.php')->run();
// routes.php
use Sodaho\Router\{Response, RouteCollector};
return function (RouteCollector $r) {
$r->get('/users/{id:int}', fn ($request, int $id) => Response::success(['id' => $id]))->name('user.show');
$r->post('/users', [UserController::class, 'store']);
};