Reputation: 255005
Realized few minutes ago that there is no GreaterOrEqualThan
validator, or a parameter in GreaterThan
validator that changes its behaviour from >
to >=
.
Why? Is it possible to compose >=
validator using basic zend framework set of validators?
Yes, guys, I know that I can write my own validator, but I'm curious about solution based on native ZF validators ;-)
Upvotes: 5
Views: 2176
Reputation: 22406
I'd set array('min' => ($value-1))
and use GreaterThan
. Maybe use a chain and add Digits
, so you make sure you're dealing with numbers. Something like this:
$value = 10;
$chain = new Zend_Validate();
$chain->addValidator(new Zend_Validate_Digits());
$chain->addValidator(new Zend_Validate_GreaterThan(array('min' => ($value-1))));
var_dump($chain->isValid($value), $chain->getMessages());
I think that's as far as you get with ZF. Wouldn't hurt to get a feature request though. Would be a nice addition. Otherwise, extend GreaterThan
and add an option.
Upvotes: 4