2011-10-08 9 views
1

私はこのようなフォームを作成しています:ファイル要素をzend形式で追加するには?

UploadFiale.php

<?php 

class Form_UploadFile extends Zend_Form { 

    public function __construct($options = null) { 

     parent::__construct($options);  
     $this->setMethod('post'); 
     $elements = array(); 

     // photo 
     $element = new Zend_Form_Element_File('photo'); 
     $element->setLabel('Photo'); 
     $element->addValidator('Count', false, 1); 
     $element->addValidator('Size', false, 102400); 
     $element->addValidator('Extension', false, 'jpg,png,gif'); 
     $elements[] = $element; 

     // submit button  
     $element = $this->CreateElement('submit', 'submit'); 
     $element->setLabel('Save'); 
     $elements[] = $element; 

     $this->addElements($elements); 
     $this->setElementDecorators(array('ViewHelper'));   
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'uploadfile-form.phtml')))); 

    } // end construct  
} // end class 
?> 

uploadfile-form.phtml

<form action=<?= $this->element->getAction() ?> method=<?= $this->element->getMethod() ?> id='AddNotificationForm' enctype='multipart/form-data' class='AjaxForm'>  
<table border='0'> 
    <tr> 
     <td><label><?= $this->element->photo->getLabel() ?></label></td> 
     <td><?= $this->element->photo; ?></td> 
    </tr> 
    <tr> 
     <td></td> 
     <td><?= $this->element->submit; ?></td> 
    </tr>  
</table>  
</form> 

私はフォームクラスを初期化して、ビューでそれをレンダリング次のエラーが発生します:

Warning: No file decorator found... unable to render file element in /project_folder/library/Zend/Form/Element.php on line 2041

同じ構造体が他のフォーム要素で動作していますが、ファイル要素では機能しません。誰かが私にここで何が間違っていると言うことができますか?

+0

を削除いずれかデコレータを「ファイル」なしで動作しないような方法で特別である

おかげで(配列( array( 'File')、 array( 'Errors') )); 'ファイル要素では、同じ警告が表示されます。ソース:http://framework.zend.com/wiki/display/ZFFAQ/Forms – Student

+0

このタイプのエラーのようです:http://forums.zend.com/viewtopic.php?f=69&t=1701 – Student

+0

あなたの答えがこれかもしれない場合http://stackoverflow.com/questions/2143462/how-do-i-use-viewscripts-on-zend-form-file-elements – vascowhite

答えて

2

Zend_Form_Element_Fileが、私はこの `$、エレメント> setDecoratorsを試してみました、それはあなたが、具体的にそれを追加したり、

$this->setElementDecorators(array('ViewHelper')); 
関連する問題