问题描述
几分钟前意识到没有 GreaterOrEqualThan
验证器,或者 GreaterThan
验证器中的参数将其行为从 >
更改为 .
Realized few minutes ago that there is no GreaterOrEqualThan
validator, or a parameter in GreaterThan
validator that changes its behaviour from >
to >=
.
为什么?是否可以使用基本的 Zend 框架验证器集组合 >=
验证器?
Why? Is it possible to compose >=
validator using basic zend framework set of validators?
是的,伙计们,我知道我可以编写自己的验证器,但我对基于原生 ZF 验证器的解决方案感到好奇;-)
Yes, guys, I know that I can write my own validator, but I'm curious about solution based on native ZF validators ;-)
推荐答案
我会设置 array('min' => ($value-1))
并使用 GreaterThan代码>.也许使用一个链并添加
Digits
,这样你就可以确保你正在处理数字.像这样:
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());
我认为这就是采埃孚所能做到的.不过,获得功能请求也无妨.将是一个不错的补充.否则,扩展 GreaterThan
并添加一个选项.
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.
这篇关于Zend Framework 中的 GreaterOrEqual 验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!