Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit687d345

Browse files
committed
minor#10810 [Validator] Explained how to use array constant in annotation (nikophil)
This PR was squashed before being merged into the 3.4 branch (closes#10810).Discussion----------[Validator] Explained how to use array constant in annotationHi,few days ago i tried to add a new feature to the `choice` validator constraint, by adding a new `choicesFromConstant` option.symfony/symfony#29658But then, i realized this was already supported.I think this should be documented, as i think a lot of people don't know this feature.thanks.Commits-------7774aab [Validator] Explained how to use array constant in annotation
2 parentse68678a +7774aab commit687d345

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎reference/constraints/Choice.rst‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ If your valid choice list is simple, you can pass them in directly via the
4747
4848
class Author
4949
{
50+
const GENRES = ['fiction', 'non-fiction'];
51+
5052
/**
5153
* @Assert\Choice({"New York", "Berlin", "Tokyo"})
5254
*/
5355
protected $city;
5456
5557
/**
56-
* @Assert\Choice(choices={"fiction", "non-fiction"}, message="Choose a valid genre.")
58+
* You can also directly provide an array constant to the "choices" option in the annotation
59+
*
60+
* @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.")
5761
*/
5862
protected $genre;
5963
}
@@ -211,7 +215,7 @@ constraint.
211215
}
212216
}
213217
214-
If the callback isstored in a different class and is static, for example ``AppBundle\Entity\Genre``,
218+
If the callback isdefined in a different class and is static, for example ``AppBundle\Entity\Genre``,
215219
you can pass the class name and the method as an array.
216220

217221
..configuration-block::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp