简体   繁体   中英

GreaterOrEqual validator in Zend Framework

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 ;-)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM