2012-01-11 5 views
2

내가 테이블을 기반으로 양식을 만들려고 간단한 젠드 양식젠드 양식

class Form_Upload extends Zend_Form 
{ 
    private $_networks = array(); 
    private $_reportYear; 
    public function __construct($options) 
    { 
     if (array_key_exists('networks', $options)) { 
      $this->_networks = $options['networks']; 
      unset($options['networks']); 
     } 
     if (array_key_exists('reportYear', $options)) { 
      $this->_reportYear = $options['reportYear']; 
      unset($options['reportYear']); 
     } 
     parent::__construct($options); 
    } 
    public function init() 
    { 
     $this->setMethod(Zend_Form::METHOD_POST); 
     $this->setAttrib('enctype', 'multipart/form-data'); 

     $this->setDecorators(array(
      'FormElements', 
      array('HtmlTag', array('tag' => 'table')), 
      'Form' 
     )); 

     // Report year 
     $reportYear = new Zend_Form_Element_Hidden('ReportYear'); 
     $reportYear->setValue($this->_reportYear); 
     $this->addElement($reportYear); 

     // Station File 
     $stationFile = new Zend_Form_Element_File('StationFile'); 
     $stationFile->setLabel('Station File') 
      ->setMaxFileSize(102400) 
      ->addValidator('Extension', false, 'csv') 
      ->setValueDisabled(true); 
     $this->addElement($stationFile); 

     $stationFileNetwork = new Zend_Form_Element_Select('StationFileNetwork'); 
     $stationFileNetwork->setLabel('Network') 
          ->addMultiOptions($this->_networks); 
     $this->addElement($stationFileNetwork); 

     $stationFileComment = new Zend_Form_Element_Textarea('StationFileComment'); 
     $stationFileComment->setLabel('Comments') 
          ->setAttrib('cols', 30) 
          ->setAttrib('rows', 5); 
     $this->addElement($stationFileComment); 

     // Configuration File 
     $configurationFile = new Zend_Form_Element_File('ConfigurationFile'); 
     $configurationFile->setLabel('Configuration File') 
      ->setMaxFileSize(102400) 
      ->addValidator('Extension', false, 'csv') 
      ->setValueDisabled(true); 
     $this->addElement($configurationFile); 

     $configurationFileNetwork = new Zend_Form_Element_Select('ConfigurationFileNetwork'); 
     $configurationFileNetwork->setLabel('Network') 
      ->addMultiOptions($this->_networks); 
     $this->addElement($configurationFileNetwork); 

     $configurationFileComment = new Zend_Form_Element_Textarea('ConfigurationFileComment'); 
     $configurationFileComment->setLabel('Comments') 
      ->setAttrib('cols', 30) 
      ->setAttrib('rows', 5); 
     $this->addElement($configurationFileComment); 

     // Measurement File 
     $measurementFile = new Zend_Form_Element_File('MeasurementFile'); 
     $measurementFile->setLabel('Measurement File') 
      ->setMaxFileSize(102400) 
      ->addValidator('Extension', false, 'csv') 
      ->setValueDisabled(true); 
     $this->addElement($measurementFile); 

     $measurementFileNetwork = new Zend_Form_Element_Select('MeasurementFileNetwork'); 
     $measurementFileNetwork->setLabel('Network') 
      ->addMultiOptions($this->_networks); 
     $this->addElement($measurementFileNetwork); 

     $measurementFileComment = new Zend_Form_Element_Textarea('MeasurementFileComment'); 
     $measurementFileComment->setLabel('Comments') 
      ->setAttrib('cols', 30) 
      ->setAttrib('rows', 5); 
     $this->addElement($measurementFileComment); 

     // Submit 
     $submit = new Zend_Form_Element_Submit('Upload'); 
     $submit->setLabel('Upload'); 
     $this->addElement($submit); 

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

    } 
} 

이 렌더링되지 않습니다. 그러나 요소 장식자를 추가하자마자

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

양식이 사라집니다. 내보기에는 <?php echo $this->form; ?> 만 있고 setElementDecorators를 제거하면 폼이 물론 표 레이아웃을 표시하지 않고 올바르게 표시됩니다.

그리고이 Tutorial - Table layout with Zend Framework form decorators

+0

컨트롤러 스크립트의 어딘가에서 $ form 변수를 할당하고 있습니까? 이 $ this-> view-> form = $ form과 비슷합니다. ? – mychiara

+1

물론, 그렇지 않으면 setElementDecorator를 제거했을 때 작동하지 않았을 것입니다. – Optimus

+0

미안 해요 - 긴 하루 였어요;) – mychiara

답변

1

내 생각을 따라 당신이 당신의 경고/예외를 표시하지 않습니다 그리고 당신은 Zend_Form_Element_File 요소에서 예외를 얻고 있다는 것입니다. 이러한 파일 요소를 포함하여 모든 요소에 데코레이터를 설정합니다. 그러나 파일 요소가 작동하려면 파일 데코레이터가 필요합니다.

setElementDecorators 뒤에있는 파일 요소의 데코레이터를 설정하고 그 결과를 확인하십시오. 또는 파일 요소를 남겨 두어 문제의 원인인지 테스트하십시오.

+0

물론! 고마워요! – Optimus