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

Commit7774aab

Browse files
nikophiljaviereguiluz
authored andcommitted
[Validator] Explained how to use array constant in annotation
1 parent239136d commit7774aab

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
@@ -46,13 +46,17 @@ If your valid choice list is simple, you can pass them in directly via the
4646
4747
class Author
4848
{
49+
const GENRES = ['fiction', 'non-fiction'];
50+
4951
/**
5052
* @Assert\Choice({"New York", "Berlin", "Tokyo"})
5153
*/
5254
protected $city;
5355
5456
/**
55-
* @Assert\Choice(choices={"fiction", "non-fiction"}, message="Choose a valid genre.")
57+
* You can also directly provide an array constant to the "choices" option in the annotation
58+
*
59+
* @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.")
5660
*/
5761
protected $genre;
5862
}
@@ -210,7 +214,7 @@ constraint.
210214
}
211215
}
212216
213-
If the callback isstored in a different class and is static, for example ``AppBundle\Entity\Genre``,
217+
If the callback isdefined in a different class and is static, for example ``AppBundle\Entity\Genre``,
214218
you can pass the class name and the method as an array.
215219

216220
..configuration-block::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp