GreaterOrEqual validator in Zend Framework

▼魔方 西西 提交于 2019-12-23 12:33:53

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5730075/greaterorequal-validator-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!