PHP code example of sodaho / php-router

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']);
};

download(string $content, string $filename, string $contentType = 'application/octet-stream', bool $inline = false)
file(string $path, ?string $filename = null, string $contentType = 'application/octet-stream', bool $inline = false,
    ?string $range = null, ?int $maxChunk = null)   // 200, 206 or 416
bash
composer