Skip to content

Commit 78e2449

Browse files
committed
add mapped route parameters and aliases
corrections Auto stash before rebase of "7.2" z
1 parent b6da1f0 commit 78e2449

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

doctrine.rst

+35
Original file line numberDiff line numberDiff 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+
864899
Updating an Object
865900
------------------
866901

0 commit comments

Comments
 (0)