1. Go to this page and download the library: Download alexoliverwd/basic-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/ */
alexoliverwd / basic-router example snippets
use AOWD\Router;
use AOWD\Attributes\Route;
class myRoutes {
#[Route('/hello-world', 'get')]
public function homeGet(): void
{
echo "GET - Hello World";
}
#[Route('/hello-world/segment/[0-9]+', 'get')]
public function homeGetSegment(Router $router): void
{
echo $router->getSegment(1);
}
#[Route('/hello-world', 'post')]
public function homePost(): void
{
echo "POST - Hello World";
}
}
$router = new Router();
$router->registerRouteController(new myRoutes());
$router->run();
use AOWD\Router;
$router = new Router();
$router->register('GET', '/', function () {
echo 'get';
});
$router->register("get", "/second/segment/[0-9]+", function () use ($router) {
echo $router->getSegment(1);
});
$router->run();