我正在使用ViewScript來裝飾我的表單元素。使用無線電元素,分隔符通常可以被覆蓋,但是當我使用ViewScript時,覆蓋忽略。使用ViewScript裝飾器時覆蓋Zend_Form無線元素上的分隔符
當我使用下面的調用和ViewScript時,無線電元素被'< br/>'分開,而不是我指定的空格。如果保留默認的裝飾器,覆蓋工作。
$this->addElement('radio', 'active', array(
'disableLoadDefaultDecorators' => true,
'decorators' => array(array('ViewScript', array('viewScript' => 'form/multi.phtml'))),
'label' => 'Active',
'required' => true,
'multiOptions' => array('1' => 'Yes', '0' => 'No',),
'value' => '1',
'separator' => ' ',
'filters' => array(),
'validators' => array(),
));
ViewScript:
<div class="field <?php echo strtolower(end(explode('_',$this->element->getType()))) ?><?php if($this->element->hasErrors()): ?> errors<?php endif; ?>" id="field_<?php echo $this->element->getId(); ?>">
<?php if (0 < strlen($this->element->getLabel())): ?>
<?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?>
<?php endif; ?>
<span class="value"><?php echo $this->{$this->element->helper}(
$this->element->getName(),
$this->element->getValue(),
$this->element->getAttribs(),
$this->element->getMultiOptions()
); ?></span>
<?php if ($this->element->hasErrors()): ?>
<?php echo $this->formErrors($this->element->getMessages()); ?>
<?php endif; ?>
<?php if (0 < strlen($this->element->getDescription())): ?>
<span class="hint"><?php echo $this->element->getDescription(); ?></span>
<?php endif; ?>
</div>
你的解決方案適用於您的情況,但使用視圖腳本時就不會奏效。感謝您發佈它,它可能會派上用場,因爲其他人試圖找到解決方案。 – Sonny 2010-06-01 13:44:58