Skip to content

Commit 2646942

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [HttpKernel] Document AsController attribute
2 parents 97dad95 + 7377ccb commit 2646942

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

controller/service.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ 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+
3150
Registering your controller as a service is the first step, but you also need to
3251
update your routing config to reference the service properly, so that Symfony
3352
knows to use it.

0 commit comments

Comments
 (0)