Skip to content

[Routing] Attributes need a routing config, too. #16454

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
Jun 10, 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
14 changes: 9 additions & 5 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ once in your application to enable them:
Symfony 5.2. Prior to this, Doctrine Annotations were the only way to
annotate controller actions with routing configuration.

This command also creates the following configuration file:
If you are using :ref:`Symfony Flex <symfony-flex>` this command also
creates the following configuration file and you're done. If you aren't
using flex or want to use attributes, the file has to be added manually.
``type: annotation`` applies for attributes, too.

.. code-block:: yaml

Expand All @@ -54,8 +57,9 @@ This command also creates the following configuration file:
resource: ../../src/Kernel.php
type: annotation

This configuration tells Symfony to look for routes defined as annotations in
any PHP class stored in the ``src/Controller/`` directory.
This configuration tells Symfony to look for routes defined as
annotations/attributes in any PHP class stored in the ``src/Controller/``
directory.

Suppose you want to define a route for the ``/blog`` URL in your application. To
do so, create a :doc:`controller class </controller>` like the following:
Expand Down Expand Up @@ -1384,7 +1388,7 @@ A possible solution is to change the parameter requirements to be more permissiv

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

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -1504,7 +1508,7 @@ when importing the routes.

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

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand Down