Zend_Validate::is() 静态检查,获取验证消息解决方法

2021-12-29 00:00:00 php zend-framework zend-validate

有谁知道在静态范围内使用 Zend_Validate 获取验证消息的方法吗?

Does anyone know of a way to get validation messages from using Zend_Validate in static scope?

Zend_Validate::is($value, $validator[0], $validator[2])

文档明确表示不能选择获取消息:http://framework.zend.com/manual/en/zend.validate.introduction.html#zend.validate.introduction.static

The docs say explicitly that getting the messages isn't an option: http://framework.zend.com/manual/en/zend.validate.introduction.html#zend.validate.introduction.static

有点令人沮丧,但我想知道是否有人知道 Zend 中用于从验证字符串获取消息的任何其他方法?

Slightly discouraging, but I was wondering if someone knew of any other methods that are inside Zend for getting messages from a validation string?

如果有人感兴趣,我正在关注一篇关于在模型级别进行验证的精彩文章:http://www.cambraca.com/2011/03/validation-in-zend-framework-model.html

I'm following a great article about validating at the model level if anyone is interested: http://www.cambraca.com/2011/03/validation-in-zend-framework-model.html

感谢您的帮助,-赛斯

推荐答案

恐怕做不到.看,消息附加到每个 Validator object - 您不能将它们附加到 class(除非您使用静态消息属性和静态 setter/getter 并将使用它).

I'm afraid it just cannot be done. See, the messages are attached to each Validator object - you cannot attach them to class (unless you make your own implementation of the validation logic with static message properties and static setter/getter for it and will use it instead).

相关文章