Skip to content

[HttpKernel] Document AsController attribute #16748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ in method parameters:
resource: '../src/Controller/'
tags: ['controller.service_arguments']

.. versionadded:: 5.3

The ``#[AsController]`` attribute was introduced in Symfony 5.3.

If you are using PHP 8.0 or later, you can use the ``#[AsController]`` PHP
attribute to automatically apply the ``controller.service_arguments`` tag to
your controller services::

// src/Controller/HelloController.php
namespace App\Controller;

use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;

#[AsController]
class HelloController
{
#[Route('/hello', name: 'hello', methods: ['GET'])]
public function index()
{
// ...
}
}

Registering your controller as a service is the first step, but you also need to
update your routing config to reference the service properly, so that Symfony
knows to use it.
Expand Down