Skip to content

Commit 7774aab

Browse files
nikophiljaviereguiluz
authored andcommitted
[Validator] Explained how to use array constant in annotation
1 parent 239136d commit 7774aab

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 is stored in a different class and is static, for example ``AppBundle\Entity\Genre``,
217+
If the callback is defined 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)