mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
42 lines
670 B
Markdown
42 lines
670 B
Markdown
|
---
|
||
|
id: c25c1315-47c9-484e-ba03-59c44c720cb5
|
||
|
title: Route
|
||
|
---
|
||
|
|
||
|
# Description
|
||
|
|
||
|
[PHP Attributes](20201110100420-php_attributes) can be used to define
|
||
|
routing.
|
||
|
|
||
|
# Syntax
|
||
|
|
||
|
``` php
|
||
|
// BEFORE: annotations defined with Doctrine Annotations library
|
||
|
use Symfony\Component\Routing\Annotation\Route;
|
||
|
|
||
|
class SomeController
|
||
|
{
|
||
|
/**
|
||
|
* @Route("/path", name="action")
|
||
|
*/
|
||
|
public function someAction()
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
``` php
|
||
|
// AFTER: annotations defined with PHP 8 attributes
|
||
|
use Symfony\Component\Routing\Annotation\Route;
|
||
|
|
||
|
class SomeController
|
||
|
{
|
||
|
#[Route('/path', name: 'action')]
|
||
|
public function someAction()
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
```
|