У меня есть простая форма Zend
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, форма отображается правильно (без разметки таблицы, конечно).
И я следил за этим
Учебное пособие - Макет таблицы с помощью декораторов форм Zend Framework