2011-09-28 3 views
6

다음 Zend Form이 오류를 발생시키는 문제가 있습니다. 문제는 "파일"요소이며 setElementDecorators를 사용하는 것입니다.젠드 파일 업로드 및 요소 데코레이터

class Products_AddForm extends Zend_Form 
{ 
    function init() { 

     // other form elements... 

     $uploadElement = new Zend_Form_Element_File('Excel'); 
     $uploadElement->setLabel('Excel'); 
     $this->addElement($uploadElement); 

     $this->setElementDecorators(array(
      'ViewHelper', 
      'Errors', 
      array(array('data' => 'HtmlTag'), array('tag' => 'td')), 
      array('Label', array('tag' => 'th')), 
      array(array('row' => 'HtmlTag'), array('tag' => 'tr')) 
     )); 



    } 
} 

오류가 발생합니다.

작동합니다 SetElementDecorators 후 마지막에 $uploadElement->addDecorator('File'); 추가
(Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0) 

, 그러나 이것은 나에게 파일 요소를 두 번 줄 것이다!

아무도 도와 줄 수 있습니까?

TIA 매트

답변

10

[파일 요소는 자신의 장식을 필요로 - Zend_Form_Decorator_File.

$this->setElementDecorators(array(
     'File', 
     'Errors', 
     array(array('data' => 'HtmlTag'), array('tag' => 'td')), 
     array('Label', array('tag' => 'th')), 
     array(array('row' => 'HtmlTag'), array('tag' => 'tr')) 
)); 

[편집]

그냥 당신이 다른 폼 요소를 사용하는 것으로 나타났습니다.

원래 코드 후, 추가

$this->getElement('Excel')->setDecorators(
    array(
     'File', 
     'Errors', 
     array(array('data' => 'HtmlTag'), array('tag' => 'td')), 
     array('Label', array('tag' => 'th')), 
     array(array('row' => 'HtmlTag'), array('tag' => 'tr')) 
    ) 
); 

그 방법은, ViewHelper 다른 모든 요소에 추가하고 파일 요소 파일 대신 사용을위한 것입니다.

+0

고마워요 4 ur 도움. 이 throw 추가 : 경고 : 폼에 의해 catch 된 예외 : 메서드 getMaxFileSize 존재하지 않습니다 스택 추적 : # 0 – frgtv10

+0

내 대답 업데이트했습니다 : –

+0

작동합니다. havnt는 zend의 문서에서 이것을 알아 차렸다!? :/ 감사! – frgtv10