解決策があるかもしれません。ファイルのアップロードは、特に zend の場合、実装とカスタマイズが難しいことが多いため、特定のデコレータを使用してフォームの動作とレンダリングを変更しました。したがって、エラーメッセージに関して必要なことは何でもできます。簡単な例:
フォーム例ファイル:
private $fileDecorators = array(
'File', array('ViewScript', array(
'viewScript' => 'forms/file.phtml',
'placement' => false)))
;
$uploadfile = new Zend_Form_Element_File('uploadfile', array(
'disableLoadDefaultDecorators' => true,
'decorators' => $this->fileDecorators,
'description' => 'form_uploadfile_description',
'label' => 'form_uploadfile_label',
'required' => true,
'destination' => '/tmp',
'filters' => array(
),
'validators' => array(
//array('StringLength', array(0, 256)),
array('Size', true, '1MB'),
array('Extension', true, 'jpg,png,gif'),
array('Count', true, 1)
)
));
$this->addElement($uploadfile);
そして、レンダリングをカスタマイズできる file.phtml デコレータ ファイルの内容:
<?php
$type=explode('_',$this->element->getType());
$myclass = 'form_item ' . strtolower(end($type));
?>
<div class="<?php echo $myclass; ?>" id="field_<?php echo $this->element->getId(); ?>">
<?php if (0 < strlen($this->element->getLabel())): ?>
<?php echo $this->formLabel($this->element->getFullyQualifiedName(), $this->element->getLabel(),array('class'=>($this->element->isRequired())?' required':""));?>
<?php endif; ?>
<div class="float_100">
<span class="file_wrapper">
<?php echo $this->content; ?>
<span class="button"><?=$this->translate('choose_an_image')?></span>
</span>
</div>
<?php if (0 < strlen($this->element->getDescription())): ?>
<div class="tooltip"><?php echo $this->element->getDescription(); ?></div>
<?php endif; ?>
<?php if (0 < strlen($this->element->getMessages())): ?>
<div class="error">
// Print your error here
</div>
<?php endif; ?>
</div>
この助けを願っています