Skip to content

Commit 4fe62c6

Browse files
committed
Add a code example for the BackendEnum argument resolver
1 parent a569d34 commit 4fe62c6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

controller/argument_value_resolver.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@ Symfony ships with the following value resolvers in the
2424
Attempts to resolve a backed enum case from a route path parameter that matches the name of the argument.
2525
Leads to a 404 Not Found response if the value isn't a valid backing value for the enum type.
2626

27+
For example, if your backed enum is::
28+
29+
namespace App\Model;
30+
31+
enum Suit: string
32+
{
33+
case Hearts = 'H';
34+
case Diamonds = 'D';
35+
case Clubs = 'C';
36+
case Spades = 'S';
37+
}
38+
39+
And your controller contains the following:
40+
41+
class CardController
42+
{
43+
#[Route('/cards/{suit}')]
44+
public function list(Suit $suit): Response
45+
{
46+
// ...
47+
}
48+
49+
// ...
50+
}
51+
52+
When requesting the ``/cards/H`` URL, the ``$suit`` variable will store the
53+
``Suit::Hearts`` case.
54+
55+
.. versionadded:: 6.1
56+
57+
The ``BackedEnumValueResolver`` was introduced in Symfony 6.1.
58+
2759
:class:`Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver\\RequestAttributeValueResolver`
2860
Attempts to find a request attribute that matches the name of the argument.
2961

0 commit comments

Comments
 (0)