热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Zend_Validate_Between奇怪的错误消息-Zend_Validate_Betweenstrangeerrormessage

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 个解决方案

#1


Zend_Form_Element_Select automatically adds an InArray validator to itself.

Zend_Form_Element_Select自动将InArray验证器添加到自身。

To set the error message for it, this should do the trick:

要为它设置错误消息,这应该可以解决问题:

$element->getValidator('InArray')->setMessage('Your inArray error message here', Zend_Validate_InArray::NOT_IN_ARRAY);

If you do not want the InArray validator at all, you can disable this behavior by either calling setRegisterInArrayValidator(false) on the element, or by passing false to the registerInArrayValidator configuration key on element creation.

如果您根本不需要InArray验证器,则可以通过在元素上调用setRegisterInArrayValidator(false)或在元素创建时将false传递给registerInArrayValidator配置键来禁用此行为。

#2


I am a newbee so I changed messages in Zend\Validate\EmailAddress.php. Afterall its email

我是newbee所以我在Zend \ Validate \ EmailAddress.php中更改了消息。毕竟它的电子邮件


推荐阅读
author-avatar
公寓朝仓音梦NQey
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有