【发布时间】:2009-06-18 15:34:18
【问题描述】:
我正在使用Zend_Validate 来验证某些表单输入(Zend Framework 版本是 1.8.2)。由于某种原因,使用Zend_Filter_Input 描述的Zend_Filter_Input 接口不起作用:
$data = $_POST;
$filters = array('*' => array('StringTrim'));
$validators = array('driverName' => array('NotEmpty','messages' => 'This should override the default message but does not!'));
$inputFilter = new Zend_Filter_Input($filters,$validators,$data);
$messages = $inputFilter->getMessages();
debug($messages); //show me the variable contents
debug($messages) 的输出:
Array
(
[driverName] => Array
(
[isEmpty] => You must give a non-empty value for field 'driverName'
)
)
无论我做什么,我都无法覆盖该消息。如果我直接使用验证器,即:
$notEmpty = new Zend_Validate_NotEmpty();
$notEmpty->setMessage('This WILL override the default validation error message');
if (!$notEmpty->isValid($_POST['driverName'])) {
$messages = $notEmpty->getMessages();
debug($messages);
}
debug($messages) 的输出:
Array
(
[isEmpty] => Please enter your name
)
底线。我可以让验证器工作,但如果没有 Zend_Filter_Input 接口验证方法的好处,我还不如编写自己的验证类!
有没有人知道为什么会发生这种情况以及如何解决?
这可能是一个错误吗?
【问题讨论】:
标签: php zend-framework validation