PHP code example of aatis / routing

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

    

aatis / routing example snippets


$response = $router->redirect($request);

class AatisController extends AbstractController
{
    // ...
}

class AatisController extends AbstractController
{
    public function hello(): void
    {
        $this->render('template/path', [
            'template_var1' => 'Hello',
            'template_var2' => 'World !'
        ]);
    }
}

class AatisController extends AbstractController
{
    public function hello(): void
    {
        $service = $this->container->get(Service::class);
    }
}

#[Route('/hello')]
public function hello(): void
{
    // ...
}

#[Route('/hello/{name}/{age}')]
public function hello(string $name, int $age): void
{
    // ...
}

#[Route('/hello/{name}/{age}')]
public function hello(Request $request, string $name, int $age): void
{
    // ...
}

#[Route('/hello/{name}/{age}')]
public function hello(Service $service, string $name, int $age, ServiceInterface $serviceImplementingInterface): void
{
    // ...
}

#[Route('/restricted', method: ['POST', 'DELETE'])]
public function restricted(): void
{
    // ...
}

$request = Request::createFromGlobals();
$requestStack = new RequestStack();

$requestStack->push($request);

class MyService
{
    public function __construct(RequestStack $requestStack)
    {
        $this->request = $requestStack->getCurrentRequest();
    }
}