Skip to content

Commit 6a5ded0

Browse files
committed
minor #17530 Add EntityValueResolver to the list of built-in value resolvers (ker0x)
This PR was merged into the 6.2 branch. Discussion ---------- Add `EntityValueResolver` to the list of built-in value resolvers Commits ------- 173ddb5 [DoctrineBridge] Add EntityValueResolver to the list of built-in value resolvers
2 parents 57691c0 + 173ddb5 commit 6a5ded0

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

controller/value_resolver.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Symfony ships with the following value resolvers in the
146146
argument list. When the action is called, the last (variadic) argument will
147147
contain all the values of this array.
148148

149-
In addition, some components and official bundles provide other value resolvers:
149+
In addition, some components, bridges and official bundles provide other value resolvers:
150150

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

162+
:class:`Symfony\\Bridge\\Doctrine\\ArgumentResolver\\EntityValueResolver`
163+
Automatically query for an entity and pass it as an argument to your controller.
164+
165+
For example, the following will query the ``Product`` entity which has ``{id}`` as primary key::
166+
167+
// src/Controller/DefaultController.php
168+
namespace App\Controller;
169+
170+
use Symfony\Component\HttpFoundation\Response;
171+
use Symfony\Component\Routing\Annotation\Route;
172+
173+
class DefaultController
174+
{
175+
#[Route('/product/{id}')]
176+
public function share(Product $product): Response
177+
{
178+
// ...
179+
}
180+
}
181+
182+
To learn more about the use of the ``EntityValueResolver``, see the dedicated
183+
section :ref:`Automatically Fetching Objects <doctrine-entity-value-resolver>`.
184+
185+
.. versionadded:: 6.2
186+
187+
The ``EntityValueResolver`` was introduced in Symfony 6.2.
188+
162189
PSR-7 Objects Resolver:
163190
Injects a Symfony HttpFoundation ``Request`` object created from a PSR-7 object
164191
of type :class:`Psr\\Http\\Message\\ServerRequestInterface`,

0 commit comments

Comments
 (0)