PHP code example of devceliojr / simplerouter

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

    

devceliojr / simplerouter example snippets




impleRouter\Application\Router;

$router = new Router;

$router->get('/', function () {
    echo 'Hello, world!';
});

$router->dispatch();

$router->get('/users/{id:number}', function ($request) {
    echo "User {$request->body->id}";
});

$router->post('/users', function () {
    echo "Creating user...";
});

$router->put('/users/{id:number}', function ($request) {
    echo "Updating user {$request->body->id}...";
});

$router->group(null, function () use ($router) {
    $router->get("/", [HomeController::class, "home"]);
});

$router->group("/admin", function () use ($router) {
    $router->get("/", [AdminController::class, "show"]);
    $router->subgroup("/financial", function () use ($router) {
        $router->get("/", [AdminController::class, "financial"]);
    });
});