My validations are defined in a yaml file like so;
# src/My/Bundle/Resources/config/validation.yml
My\Bundle\Model\Foo:
properties:
id:
- NotBlank:
groups: [add]
min_time:
- Range:
min: 0
max: 99
minMessage: "Min time must be greater than {{ limit }}"
maxMessage: "Min time must be less than {{ limit }}"
groups: [add]
max_time:
- GreaterThan:
value: min_time
groups: [add]
How do I use the validator constraint GreaterThan
to check against another property?
E.g make sure max_time is greater than min_time?
I know I can create a custom constraint validator, but surely you can do it using the GreaterThan
constraint.
Hopefully I am missing something really simple here
Try GreaterThan constraint with option propertyPath:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Assert\DateTime()
* @Assert\GreaterThan(propertyPath="minTime")
*/
protected $maxTime;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With