File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -861,6 +861,41 @@ control behavior:
861861
862862 The ``message `` option was introduced in Symfony 7.1.
863863
864+ Mapped Route Parameters
865+ ~~~~~~~~~~~~~~~~~~~~~~~
866+
867+ When many route parameters are used to find more than one entity,
868+ it is mandatory to use #[MapEntity] attributes and this can become cumbersome::
869+
870+ #[Route('/document/{slug}/{id}-{name}/')]
871+ public function showDocument(
872+ #[MapEntity(mapping: ['slug' => 'slug'])]
873+ Category $category,
874+ #[MapEntity(mapping: ['id' => 'id', 'name' => 'name'])]
875+ Document $document,
876+ ): Response
877+ {
878+ // the database queries in this case would be:
879+ // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']);
880+ // $category = $categoryRepository->findOneBy(['slug' => 'the slug']);
881+ }
882+
883+ As an alternative, you can also use Mapped Route Parameters.
884+
885+ When adding route parameters, you can now define the mapping between the route parameter and the controller argument::
886+
887+ #[Route('/document/{slug:category}/{id:document}-{name:document}/')]
888+ public function showDocument(Document $document, Category $category): Response
889+ {
890+ // the database queries in this case would be:
891+ // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']);
892+ // $category = $categoryRepository->findOneBy(['slug' => 'the slug']);
893+ }
894+
895+ .. versionadded :: 7.1
896+
897+ The ``Mapped Route Parameters `` was introduced in Symfony 7.1.
898+
864899Updating an Object
865900------------------
866901
You can’t perform that action at this time.
0 commit comments