PHP code example of pedroquezado / router

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

    

pedroquezado / router example snippets




roQuezado\Code\Router\Router;

$router = new Router('example.com');
$router->get('/', function () {
    echo 'Hello, world!';
});
$router->post('/user', 'UserController::create');
$router->put('/user/{id}', 'UserController::update');
$router->delete('/user/{id}', function ($id) {
    echo "Deleting user with ID: $id";
});

$router->run();
 
$router = new Router("https://www.yourdomain.com"); 
 
$router->get("/home", function () {
    // Handle the GET /home request
});
 
$router->post('/user', 'UserController::create');
 
$router->namespace('App\Controllers');
$router->get('/users', 'UserController::index');
$router->get('/products', 'ProductController::index');

$router->namespace('App\Forms');
$router->get('/users', 'UserForms::index');
$router->get('/products', 'ProductForms::index');

$router->run();