-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Add alias in {foo:bar}
syntax in route parameter
#59904
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
Conversation
{foo:bar}
syntax in route parameter
src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php
Outdated
Show resolved
Hide resolved
Is it a choice to not use named capture in Route.php ? |
I'm sorry I don't get this feature, can you expand on what this provides? |
I need a route with {id:foo} and {id:bar} |
Why? From a routing PoV, that's undefined: how would you generate just a route for example? |
that's my proposal, instead of {id:foo} and {id:bar} witch can be impossible, I can have {fooId:foo.id} and {barId:bar.id}. |
IIUC, this use case can me handled by: You do not need to alias anything, just use the proper name for ids. |
it's just a shortcut to not write Many Map Entity to map alias with field name |
If your field is id in both classes you must add a mapentity for each arguments. I just found it quicker to write, and not have to put an attribute to each argument witch is less readable IMO |
The description of the PR should be improved IMHO. |
Do you prefer this new description ? |
src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
Outdated
Show resolved
Hide resolved
3cfef01
to
4e2c638
Compare
Thank you @eltharin. |
Since #54720 we can/have to write route parameters with "destination" as slug:bar,
but if we have two properties with same name example :
/search-book/{name:author}/{name:category}
we get the error message : Route pattern "/search-book/{name}/{name}" cannot reference variable name "name" more than once.
Actually to prevent this error we have to use MapEntity as :
and we have to remove Mapped Route Parameters :
#[Route('/search-book/{authorName}/{categoryName}')
This PR proposal is to remove MapEntity attributes and keep Mapped Route Parameters by adding an alias on it :
/search-book/{authorName:author.name}/{categoryName:category.name}
With that, EntityValueResolver will search name in author Entity and name in Category Entity.
We can have url with :
{{ path('bookSearch', {authorName: 'KING', categoryName: 'Horror'}) }}