2012-08-13 100 views
0

可能重複:
Zend form validationZend框架:刪除驗證信息

這是我的文件格式:

$file = new Zend_Form_Element_File('file', array(
       'required' => true, 
       'MaxFileSize' => 4194304, 
       'validators' => array(
        array('Count', false, 1), 
        array('Size', false, 4194304), 
        array('Extension', false, 'gif,jpg,png'), 
        array('ImageSize', false, array('minwidth' => 40, 
          'minheight' => 40, 
          'maxwidth' => 90, 
          'maxheight' => 90))))); 

如何刪除驗證消息?

+0

你的意思是說,如何刪除消息驗證失敗? – Karma 2012-08-13 08:12:15

+0

我不知道,文件驗證器Size,Extension,ImageSze添加英文信息我需要刪除它們。 – Defense 2012-08-13 09:29:53

回答

1

每個驗證器的最後一個參數可以是一個數組。其中一個可以傳遞的參數是'messages',它是一組表示每個錯誤的驗證器特定常量,以及錯誤消息的字符串。您可以通過查看驗證器類(例如Zend/Validate/File/ImageSize.php)來獲取錯誤代碼列表。在你的情況下,這些將是:

$file = new Zend_Form_Element_File('file', array(
       'required' => false, //we will add this as a custom validator so we can over-ride the error message 
       'MaxFileSize' => 4194304, 
       'validators' => array(
        array('NotEmpty', true, array('messages' => array('isEmpty' => "Your error message here"))) 
        array('Count', false, array(count => 1, 'messages' => array('fileCountTooFew' => "Too few files, minimum '%min%' are expected but '%count%' are given", 'fileCountTooMany' => "Too many files, maximum '%max%' are allowed but '%count%' are given"))), 
        array('Size', false, array('size' => 4194304, 'messages'=> array('fileSizeTooBig' => "", 'fileSizeTooSmall' => "", 'fileSizeNotFound' => ""))), 
        array('Extension', false, array('extension' => 'gif,jpg,png', 'messages' => array('fileExtensionFalse' => "", 'fileExtensionNotFound' => ""))), 
        array('ImageSize', false, array('minwidth' => 40, 
          'minheight' => 40, 
          'maxwidth' => 90, 
          'maxheight' => 90, 
          'messages' => array(
           'fileImageSizeWidthTooBig' => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected", 
           'fileImageSizeWidthTooSmall' => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected", 
           'fileImageSizeHeightTooBig' => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected", 
           'fileImageSizeHeightTooSmall' => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected", 
           'fileImageSizeNotDetected'  => "The size of image '%value%' could not be detected", 
           'fileImageSizeNotReadable'  => "File '%value%' can not be read", 
          ) 
         ) 
        ) 
       ) 
      ) 
     ); 
+0

謝謝,問題已解決。 – Defense 2012-08-13 10:39:21