Skip to content

Pass Request to EntityValueResolver #18991

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

Merged
Merged
Changes from all commits
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
17 changes: 17 additions & 0 deletions doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,23 @@ In the example above, the ``$product`` argument is handled automatically,
but ``$comment`` is configured with the attribute since they cannot both follow
the default convention.

If you need to get other information from the request to query the database, you
can also access to the request in your expression thanks to the ``request``
variable. Let's say you pass the page limit of a list in a query parameter::

#[Route('/product/{id}/comments')]
public function show(
Product $product,
#[MapEntity(expr: 'repository.findBy(["product_id" => id], null, request.query.get("limit", 10)')]
iterable $comments
): Response {
}

.. versionadded:: 6.4

The support for the ``request`` variable in expressions was introduced
in Symfony 6.4.

MapEntity Options
~~~~~~~~~~~~~~~~~

Expand Down