Skip to content

[Routing] Add the 'attribute' value in routing annotation loaders #16646

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
Mar 25, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ hold the kernel. Now it looks like this::
$routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml')->prefix('/_profiler');
}

// load the annotation routes
$routes->import(__DIR__.'/Controller/', 'annotation');
// load the routes defined as PHP attributes
// (use 'annotation' as the second argument if you define routes as annotations)
$routes->import(__DIR__.'/Controller/', 'attribute');
}

// optional, to use the standard Symfony cache directory
Expand Down
10 changes: 9 additions & 1 deletion routing/custom_route_loader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ Symfony provides several route loaders for the most common needs:
// loads routes from the given routing file stored in some bundle
$routes->import('@AcmeBundle/Resources/config/routing.yaml');

// loads routes from the PHP annotations of the controllers found in that directory
// loads routes from the PHP attributes (#[Route(...)]) of the controllers found in that directory
$routes->import('../src/Controller/', 'attribute');

// loads routes from the PHP annotations (@Route(...)) of the controllers found in that directory
$routes->import('../src/Controller/', 'annotation');

// loads routes from the YAML or XML files found in that directory
Expand All @@ -80,6 +83,11 @@ Symfony provides several route loaders for the most common needs:
$routes->import('@AcmeOtherBundle/Resources/config/routing/', 'directory');
};

.. versionadded:: 6.1

The ``attribute`` value of the second argument of ``import()`` was introduced
in Symfony 6.1.

.. note::

When importing resources, the key (e.g. ``app_file``) is the name of the collection.
Expand Down