diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 9c41bca90d3..521fb5e8011 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -46,13 +46,17 @@ If your valid choice list is simple, you can pass them in directly via the class Author { + const GENRES = ['fiction', 'non-fiction']; + /** * @Assert\Choice({"New York", "Berlin", "Tokyo"}) */ protected $city; /** - * @Assert\Choice(choices={"fiction", "non-fiction"}, message="Choose a valid genre.") + * You can also directly provide an array constant to the "choices" option in the annotation + * + * @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.") */ protected $genre; } @@ -210,7 +214,7 @@ constraint. } } -If the callback is stored in a different class and is static, for example ``AppBundle\Entity\Genre``, +If the callback is defined in a different class and is static, for example ``AppBundle\Entity\Genre``, you can pass the class name and the method as an array. .. configuration-block::
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: