Commit 5d4973c
committed
feature #59904 [Routing] Add alias in
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{foo:bar} syntax in route parameter (eltharin)2 files changed
+31
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
422 | | - | |
423 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
424 | 424 | | |
425 | | - | |
426 | | - | |
| 425 | + | |
| 426 | + | |
427 | 427 | | |
428 | | - | |
429 | | - | |
| 428 | + | |
| 429 | + | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
1014 | | - | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1015 | 1038 | | |
1016 | 1039 | | |
1017 | 1040 | | |
| |||
0 commit comments