-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Explained how to use array constant in annotation #10810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,7 +210,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:: | ||
|
@@ -279,6 +279,35 @@ you can pass the class name and the method as an array. | |
} | ||
} | ||
|
||
Supplying the Choices from an Array Constant | ||
-------------------------------------------- | ||
|
||
You can also directly provide a constant containing an array to the ``choices`` option in the annotation:: | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
HeahDude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
const GENRES = ['action', 'comedy']; | ||
|
||
/** | ||
* @Assert\Choice(choices=Author::GENRES) | ||
*/ | ||
protected $genre; | ||
} | ||
|
||
.. warning:: | ||
|
||
The constant in the option is used without quotes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about both inside note instead of warning? warning can be misunderstood There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean in the same note or two different notes ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean both inside the same note ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same i think |
||
|
||
.. note:: | ||
|
||
If the constant is defined in a different class, you can pass the fully qualified class name. | ||
|
||
|
||
Available Options | ||
----------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array constant in lower case is better i think, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually i've wrote like this, to be consistent with the title above which is
Supplying the Choices with a Callback Function