mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 04:56:23 +00:00
42 lines
687 B
Markdown
42 lines
687 B
Markdown
---
|
|
date: 2020-11-17
|
|
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()
|
|
{
|
|
// ...
|
|
}
|
|
}
|
|
```
|