Skip to content

Add EntityValueResolver to the list of built-in value resolvers #17530

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 1 commit into from
Dec 8, 2022
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
29 changes: 28 additions & 1 deletion controller/value_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Symfony ships with the following value resolvers in the
argument list. When the action is called, the last (variadic) argument will
contain all the values of this array.

In addition, some components and official bundles provide other value resolvers:
In addition, some components, bridges and official bundles provide other value resolvers:

:class:`Symfony\\Component\\Security\\Http\\Controller\\UserValueResolver`
Injects the object that represents the current logged in user if type-hinted
Expand All @@ -159,6 +159,33 @@ In addition, some components and official bundles provide other value resolvers:
user has a user class not matching the type-hinted class, an ``AccessDeniedException``
is thrown by the resolver to prevent access to the controller.

:class:`Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver`
Automatically query for an entity and pass it as an argument to your controller.

For example, the following will query the ``Product`` entity which has ``{id}`` as primary key::

// src/Controller/DefaultController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController
{
#[Route('/product/{id}')]
public function share(Product $product): Response
{
// ...
}
}

To learn more about the use of the ``EntityValueResolver``, see the dedicated
section :ref:`Automatically Fetching Objects <doctrine-entity-value-resolver>`.

.. versionadded:: 6.2

The ``EntityValueResolver`` was introduced in Symfony 6.2.

PSR-7 Objects Resolver:
Injects a Symfony HttpFoundation ``Request`` object created from a PSR-7 object
of type :class:`Psr\\Http\\Message\\ServerRequestInterface`,
Expand Down