我使用Zend_Validate
來驗證某些表單輸入(Zend Framework版本是1.8.2)。出於某種原因,使用Zend_Filter_Input
接口描述here不起作用:爲什麼我無法覆蓋默認的驗證錯誤消息?
$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
接口驗證方法的好處,我不妨寫我自己的驗證類!
有沒有人有一個線索,爲什麼發生這種情況,以及如何解決它?
它可能是一個錯誤?
@Jason - 謝謝你的詳細信息及正確答案。 $ options參數釘住了它。完美,再次感謝:) – karim79 2009-06-18 15:56:29