Skip to content

Commit cd0d044

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

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

routing.rst

Lines changed: 13 additions & 8 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:

0 commit comments

Comments
 (0)