wiki/content/20201117105045-rout.md

685 B

date id title
20201117 c25c1315-47c9-484e-ba03-59c44c720cb5 Route

Description

PHP Attributes can be used to define routing.

Syntax

// BEFORE: annotations defined with Doctrine Annotations library
use Symfony\Component\Routing\Annotation\Route;

class SomeController
{
    /**
     * @Route("/path", name="action")
     */
    public function someAction()
    {
        // ...
    }
}
// AFTER: annotations defined with PHP 8 attributes
use Symfony\Component\Routing\Annotation\Route;

class SomeController
{
    #[Route('/path', name: 'action')]
    public function someAction()
    {
        // ...
    }
}