Skip to content

[Routing] Add FQCN and FQCN::method aliases when applicable #18822

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
Sep 5, 2023
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
28 changes: 28 additions & 0 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,34 @@ For that reason each route has an internal name that must be unique in the
application. If you don't set the route name explicitly with the ``name``
option, Symfony generates an automatic name based on the controller and action.

Symfony declares aliases based on the FQCN if the target class has an
``__invoke()`` method that adds a route **and** if the target class added
one route exactly. Symfony also automatically adds a alias for every method
that defines only one route. This means that for the following class::

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

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

final class MainController extends AbstractController
{
#[Route('/', name: 'homepage')]
public function homepage(): Response
{
// ...
}
}

An alias named ``App\Controller\MainController::homepage`` will be declared in
the router.

.. versionadded:: 6.4

The automatic declaration of aliases based on FQCNs was introduced in
Symfony 6.4.

Generating URLs in Controllers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down