Skip to content

Commit 2fd8d39

Browse files
committed
minor #16454 [Routing] Attributes need a routing config, too. (Basster)
This PR was merged into the 5.4 branch. Discussion ---------- [Routing] Attributes need a routing config, too. I came across this missing piece of information, as I created my first Symfony skeleton app since ages with a current PHP version. If you want to use attributes, you have to define a routing config, as well, but - as I read this part of the Routing documentation, I thought, I only need this file when using annotations. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- 1ba8dd9 hint about creating config/routes/annotations.yaml as well, when using attributes without doctrine/annotations.
2 parents c8f4342 + 1ba8dd9 commit 2fd8d39

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

routing.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ once in your application to enable them:
4141
Symfony 5.2. Prior to this, Doctrine Annotations were the only way to
4242
annotate controller actions with routing configuration.
4343

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

4649
.. code-block:: yaml
4750
@@ -54,8 +57,9 @@ This command also creates the following configuration file:
5457
resource: ../../src/Kernel.php
5558
type: annotation
5659
57-
This configuration tells Symfony to look for routes defined as annotations in
58-
any PHP class stored in the ``src/Controller/`` directory.
60+
This configuration tells Symfony to look for routes defined as
61+
annotations/attributes in any PHP class stored in the ``src/Controller/``
62+
directory.
5963

6064
Suppose you want to define a route for the ``/blog`` URL in your application. To
6165
do so, create a :doc:`controller class </controller>` like the following:
@@ -1395,7 +1399,7 @@ A possible solution is to change the parameter requirements to be more permissiv
13951399
13961400
// src/Controller/DefaultController.php
13971401
namespace App\Controller;
1398-
1402+
13991403
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
14001404
use Symfony\Component\HttpFoundation\Response;
14011405
use Symfony\Component\Routing\Annotation\Route;
@@ -1515,7 +1519,7 @@ when importing the routes.
15151519
15161520
// src/Controller/BlogController.php
15171521
namespace App\Controller;
1518-
1522+
15191523
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15201524
use Symfony\Component\HttpFoundation\Response;
15211525
use Symfony\Component\Routing\Annotation\Route;

0 commit comments

Comments
 (0)