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;
use AOWD\Attributes\Route;
class getRoutes {
#[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);
}
}
class postRoutes {
#[Route('/hello-world', 'post')]
public function homePost(): void
{
echo "POST - Hello World";
}
}
$router = new Router();
$router->registerRouteController(new getRoutes(), new postRoutes());
$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();
use AOWD\Interfaces\Middleware as MiddlewareInterface;
class helloWorld implements MiddlewareInterface
{
public function handle(): void
{
echo "Hello World ";
}
}
use AOWD\Attributes\Route;
use AOWD\Attributes\Middleware;
class myRoutes {
#[Route('/hello-world-middleware', 'get')]
#[Middleware(helloWorld::class)]
public function homeGetMiddleware(): void
{
echo "GET";
}
}
use AOWD\Router;
$router = new Router();
$router->registerRouteController(new myRoutes());
$router->run();
use AOWD\Router;
use AOWD\Attributes\Route;
use AOWD\Attributes\Middleware;
use AOWD\Interfaces\Middleware as MiddlewareInterface;
class helloWorld implements MiddlewareInterface
{
public function handle(): void
{
echo "Hello World ";
}
}
class myRoutes {
#[Route('/hello-world-middleware', 'get')]
#[Middleware(helloWorld::class)]
public function homeGetMiddleware(): void
{
echo "GET";
}
}
$router = new Router();
$router->registerRouteController(new myRoutes());
$router->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.