You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #59904 [Routing] Add alias in {foo:bar} syntax in route parameter (eltharin)
This PR was squashed before being merged into the 7.3 branch.
Discussion
----------
[Routing] Add alias in `{foo:bar}` syntax in route parameter
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| License | MIT
Since symfony/symfony#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 :
```php
public function bookSearch(
#[MapEntity(mapping: ['authorName' => 'name'])]
Author $author,
#[MapEntity(mapping: ['categoryName' => 'name'])]
Category $category): Response
{
```
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'}) }}`
Commits
-------
4e2c6386912 [Routing] Add alias in `{foo:bar}` syntax in route parameter
0 commit comments