Skip to content

[Routing] add mapped route parameters and aliases #20812

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

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update from comments
  • Loading branch information
eltharin committed Mar 25, 2025
commit 286ba1b6b95a0b20c6013b504acd08a17bbc14bb
14 changes: 6 additions & 8 deletions doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -875,26 +875,24 @@ it is mandatory to use ``#[MapEntity]`` attributes and this can become cumbersom
Document $document,
): Response
{
// the database queries in this case would be:
// this would result in the following database queries:
// $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']);
// $category = $categoryRepository->findOneBy(['slug' => 'the slug']);
}

As an alternative, you can also use Mapped Route Parameters.

When adding route parameters, you can now define the mapping between the route parameter and the controller argument::
By using mapped route parameters, you can define the mapping between the route parameter and the controller argument::

#[Route('/document/{slug:category}/{id:document}-{name:document}')]
public function showDocument(Document $document, Category $category): Response
{
// the database queries in this case would be:
// this would result in the following database queries:
// $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']);
// $category = $categoryRepository->findOneBy(['slug' => 'the slug']);
}

.. versionadded:: 7.1

The mapped route parameters were introduced in Symfony 7.1.
Mapped route parameters were introduced in Symfony 7.1.

But when two properties have the same name, you will catach an error if you try ::

Expand All @@ -914,7 +912,7 @@ In this case we have to return to MapEntiy::
Document $document,
): Response
{
// the database queries in this case would be:
// this would result in the following database queries:
// $document = $documentRepository->findOneBy(['id' => 'the id', 'slug' => 'the slug document']);
// $category = $categoryRepository->findOneBy(['slug' => 'the slug category']);
}
Expand All @@ -926,7 +924,7 @@ When adding route parameters, you can now define the mapping between the route p
#[Route('/document/{slugCategory:category.slug}/{id:document}-{slugDocument:document.slug}')]
public function showDocument(Document $document, Category $category): Response
{
// the database queries in this case would be:
// this would result in the following database queries:
// $document = $documentRepository->findOneBy(['id' => 'the id', 'slug' => 'the slug document']);
// $category = $categoryRepository->findOneBy(['slug' => 'the slug category']);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy