作者:公寓朝仓音梦NQey | 来源:互联网 | 2023-05-18 19:03
IamexperimentingwiththeZend_Validate_Betweenclass.我正在试验Zend_Validate_Between类。Isetitupt
I am experimenting with the Zend_Validate_Between class.
我正在试验Zend_Validate_Between类。
I set it up thusly:
我这样设置了:
$scoreBetweenValidator = new Zend_Validate_Between(-3, 3, true);
so the validator should only accept values between -3 and 3, inclusive.
所以验证器应该只接受介于-3和3之间的值。
On an invalid value I got a '%value%' was not found in the haystack error message, which I think belongs to the Zend_Validate_InArray class (Zend_Validate_InArray::NOT_IN_ARRAY).
在无效值上,我在haystack错误消息中找不到'%value%',我认为该消息属于Zend_Validate_InArray类(Zend_Validate_InArray :: NOT_IN_ARRAY)。
My problem is that I wish to use custom error messages with the setMessages method, but I don't know how I could set it up for this seemingly foreign message key.
我的问题是我希望使用setMessages方法使用自定义错误消息,但我不知道如何为这个看似外来的消息密钥设置它。
I tried this:
我试过这个:
$scoreBetweenValidator->setMessages(array(
Zend_Validate_Between::NOT_BETWEEN_STRICT => 'my custom msg',
Zend_Validate_Between::NOT_BETWEEN => 'my other custom msg',
//'notInArray' => "doesn't work"
//Zend_Validate_InArray::NOT_IN_ARRAY => "also doesn't work"
));
but I got a No message template exists for key 'notInArray' exception.
但我得到一个没有消息模板存在关键'notInArray'异常。
What is the preferred solution for setting custom validation messages in Zend Framework?
在Zend Framework中设置自定义验证消息的首选解决方案是什么?
As a reply to Jason:
作为对杰森的回复:
A Zend_Form_Element_Select is inside a Zend_Form class attached with addElements method.
Zend_Form_Element_Select位于使用addElements方法附加的Zend_Form类中。
The form doesn't have any other elements just this one, and it doesn't have any other validators, just the Between.
表单中没有任何其他元素,它没有任何其他验证器,只有Between。
The select's options are all valid by default, but when I tweak the option value (with Firebug) and set an invalid value (as a self-hacking attempt) I receive the notInArray exception.
select的选项在默认情况下都是有效的,但是当我调整选项值(使用Firebug)并设置无效值(作为自我黑客尝试)时,我收到notInArray异常。
2 个解决方案