-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Route Name Prefixing #19612
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
Comments
+1 for having that feature in the routing component. I have a similar use case here, where I need to import some routes from bundles for different hosts with different prefixes, thus the last import wins (because the route name is the same). Currently an alternative approach could be to
|
The use case seems legit to me. |
If you have enabled FOSRestBundle in your application you can use name_prefix with "type: rest" with any route collections, it's not necessary to use FOS routing loader only with only rest route collections. Or if you don't have this bundle, you still can add custom routing loader like FOS does. |
@alexhoma and me will develop this feature. |
I can have a go at that, I'd like to have something similar as well. |
Here we go: #25178 :) |
…ation (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #25178). Discussion ---------- [Routing] Allow to set name prefixes from the configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19612 | License | MIT | Doc PR | ø This allows setting name prefixes to routes while importing them. Typically, we can then import multiple times a similar file. This was originally requested by 🎸 @chrisguitarguy in #19612 ```yaml app: resource: ../controller/routing.yml api: resource: ../controller/routing.yml name_prefix: api_ prefix: /api ``` ```xml <?xml version="1.0" encoding="UTF-8" ?> <routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> <import resource="../controller/routing.xml" /> <import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" /> </routes> ``` Commits ------- 880d7e7 [Routing] Allow to set name prefixes from the configuration
I think I have a bug related with this feature. If I go only for the route prefix it works without any problem # config/routes.yaml
admin:
prefix: /admin
resource: ../src/Controller/Admin
type: annotation The router debug gives me the following output:
The problem comes when I add the # config/routes.yaml
admin:
name_prefix: admin_
prefix: /admin
resource: ../src/Controller/Admin
type: annotation The router debug gives the following output, and I can verify that the URLs are duplicated:
|
@devnix please open a new issue for this |
This is a feature request/suggestion.
It would pretty nifty to be able to prefix route IDs/names on import. The idea is that the same routing resource could be imported multiple times and generate unique route names.
For example: if you have a typical form login on one host for a UI and a stateless API token authentication on another. You might want to share the same routing config for your API between the two hosts.
Right now this can't be done. The second import overrides all the named routes in the first. Ideally I'd like to be able to do this...
All routes in the second import would get the ID
api.{original_id_attribute_value}
.The text was updated successfully, but these errors were encountered: