Skip to content

Commit b54f465

Browse files
authored
Revise routing configuration and attributes usage (routing.controllers)
Updated routing configuration details and corrected file paths.|Q |A| |Branch? |7.4| |Bug fix? |no| |New feature? |no| |Deprecations? |no| I|ssues |-| |License |MIT| Updated routing configuration details controllers: resource: routing.controllers Issue : #21558
1 parent 3497411 commit b54f465

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

routing.rst

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,17 @@ Creating Routes as Attributes
3030
PHP attributes allow you to define routes next to the code of the
3131
:doc:`controllers </controller>` associated to those routes.
3232

33-
You need to add a bit of configuration to your project before using them. If your
33+
You don't need to add any configuration to your project before using them. If your
3434
project uses :ref:`Symfony Flex <symfony-flex>`, this file is already created for you.
35-
Otherwise, create the following file manually:
3635

3736
.. code-block:: yaml
3837
39-
# config/routes/attributes.yaml
38+
# config/routes.yaml
4039
controllers:
41-
resource:
42-
path: ../../src/Controller/
43-
namespace: App\Controller
44-
type: attribute
40+
resource: routing.controllers
4541
46-
kernel:
47-
resource: App\Kernel
48-
type: attribute
49-
50-
This configuration tells Symfony to look for routes defined as attributes on
51-
classes declared in the ``App\Controller`` namespace and stored in the
52-
``src/Controller/`` directory which follows the PSR-4 standard. The kernel can
53-
act as a controller too, which is especially useful for small applications that
54-
use Symfony as a microframework.
42+
This configuration tells Symfony to enables auto-registration of ``#[Route]`` attribute of controllers,
43+
independently of where they are located in the app.
5544

5645
Suppose you want to define a route for the ``/blog`` URL in your application. To
5746
do so, create a :doc:`controller class </controller>` like the following:
@@ -89,7 +78,10 @@ the ``list()`` method of the ``BlogController`` class.
8978
.. warning::
9079

9180
If you define multiple PHP classes in the same file, Symfony only loads the
92-
routes of the first class, ignoring all the other routes.
81+
routes of the first class, ignoring all the other routes.The route attribute
82+
is always wins over route with yaml, xml or PHP file and Symfony will always
83+
load the route attribute.
84+
9385

9486
The route name (``blog_list``) is not important for now, but it will be
9587
essential later when :ref:`generating URLs <routing-generating-urls>`. You only

0 commit comments

Comments
 (0)