Skip to content

Commit e163de4

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [HttpKernel] Document AsController attribute
2 parents fd9b6cc + 160d849 commit e163de4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

controller/service.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ in method parameters:
2828
resource: '../src/Controller/'
2929
tags: ['controller.service_arguments']
3030
31+
If you prefer, you can use the ``#[AsController]`` PHP attribute to automatically
32+
apply the ``controller.service_arguments`` tag to your controller services::
33+
34+
// src/Controller/HelloController.php
35+
namespace App\Controller;
36+
37+
use Symfony\Component\HttpKernel\Attribute\AsController;
38+
use Symfony\Component\Routing\Annotation\Route;
39+
40+
#[AsController]
41+
class HelloController
42+
{
43+
#[Route('/hello', name: 'hello', methods: ['GET'])]
44+
public function index()
45+
{
46+
// ...
47+
}
48+
}
49+
50+
.. versionadded:: 5.3
51+
52+
The ``#[AsController]`` attribute was introduced in Symfony 5.3.
53+
3154
Registering your controller as a service is the first step, but you also need to
3255
update your routing config to reference the service properly, so that Symfony
3356
knows to use it.

0 commit comments

Comments
 (0)