You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validation groups allows us to define groups on individual properties of objects as per the following documented example:
class User implements UserInterface
{
#[Assert\Email(groups: ['registration'])]
private $email;
// $city belongs to special group "Default"
#[Assert\Length(min: 2)]
private $city;
We can then validate the registration group specifically by calling $validator->validate($author, null, ['registration']);, or we can validate any properties which do not have an explicit group configured by using the group name Default or not specifying a group name, e.g. $validator->validate($author, null, ['Default']);, or just $validator->validate($author);
But at the moment, if we want to validate both groups, we'd have to use $validator->validate($author, null, ['Default', 'registration']);
This is fine when you only have maybe two or three groups to work with, including Default, but gets messy when you have an arbitrarily larger number of groups.
At the moment, if you want to easily validate all groups, there is no built-in option for doing this except to either list every group in the call to validate(), or to add a group name such as all to every single property.
Would be nice if we could do $validator->validate($author, null, ['All']); or similar as a special group name which automatically applied validation to all properties, regardless of groups.
Uh oh!
There was an error while loading. Please reload this page.
Description
https://symfony.com/doc/current/validation/groups.html
Validation groups allows us to define groups on individual properties of objects as per the following documented example:
We can then validate the registration group specifically by calling
$validator->validate($author, null, ['registration']);
, or we can validate any properties which do not have an explicit group configured by using the group nameDefault
or not specifying a group name, e.g.$validator->validate($author, null, ['Default']);
, or just$validator->validate($author);
But at the moment, if we want to validate both groups, we'd have to use
$validator->validate($author, null, ['Default', 'registration']);
This is fine when you only have maybe two or three groups to work with, including
Default
, but gets messy when you have an arbitrarily larger number of groups.At the moment, if you want to easily validate all groups, there is no built-in option for doing this except to either list every group in the call to
validate()
, or to add a group name such asall
to every single property.Would be nice if we could do
$validator->validate($author, null, ['All']);
or similar as a special group name which automatically applied validation to all properties, regardless of groups.Example
The text was updated successfully, but these errors were encountered: