Skip to content

Commit 0544743

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: hint about creating config/routes/annotations.yaml as well, when using attributes without doctrine/annotations.
2 parents 5650449 + f0145cf commit 0544743

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

routing.rst

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ because it's convenient to put the route and controller in the same place.
2424
Creating Routes as Attributes or Annotations
2525
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2626

27-
On PHP 8, you can use native attributes to configure routes right away. On
28-
PHP 7, where attributes are not available, you can use annotations instead,
29-
provided by the Doctrine Annotations library.
27+
PHP attributes and annotations allow to define routes next to the code of the
28+
:doc:`controllers </controller>` associated to those routes. Attributes are
29+
native in PHP 8 and higher versions, so you can use them right away.
3030

31-
In case you want to use annotations instead of attributes, run this command
32-
once in your application to enable them:
31+
In PHP 7 and earlier versions you can use annotations (via the Doctrine Annotations
32+
library), but first you'll need to install the following dependency in your project:
3333

3434
.. code-block:: terminal
3535
3636
$ composer require doctrine/annotations
3737
38-
This command also creates the following configuration file:
38+
Regardless of what you use (attributes or annotations) you need to add a bit of
39+
configuration to your project before using them. If your project uses
40+
:ref:`Symfony Flex <symfony-flex>`, this file is already created for you.
41+
Otherwise, create the following file manually (the ``type: annotation`` option
42+
also applies to attributes, so you can keep it):
3943

4044
.. code-block:: yaml
4145
@@ -48,8 +52,9 @@ This command also creates the following configuration file:
4852
resource: ../../src/Kernel.php
4953
type: annotation
5054
51-
This configuration tells Symfony to look for routes defined as annotations in
52-
any PHP class stored in the ``src/Controller/`` directory.
55+
This configuration tells Symfony to look for routes defined as
56+
annotations/attributes in any PHP class stored in the ``src/Controller/``
57+
directory.
5358

5459
Suppose you want to define a route for the ``/blog`` URL in your application. To
5560
do so, create a :doc:`controller class </controller>` like the following:
@@ -1385,7 +1390,7 @@ A possible solution is to change the parameter requirements to be more permissiv
13851390
13861391
// src/Controller/DefaultController.php
13871392
namespace App\Controller;
1388-
1393+
13891394
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13901395
use Symfony\Component\HttpFoundation\Response;
13911396
use Symfony\Component\Routing\Annotation\Route;
@@ -1505,7 +1510,7 @@ when importing the routes.
15051510
15061511
// src/Controller/BlogController.php
15071512
namespace App\Controller;
1508-
1513+
15091514
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15101515
use Symfony\Component\HttpFoundation\Response;
15111516
use Symfony\Component\Routing\Annotation\Route;

0 commit comments

Comments
 (0)