问题描述
我正在使用ViewScripts装饰我的表单元素.对于单选元素,分隔符通常可以被覆盖,但是当我使用ViewScript时,覆盖将被忽略.
I am using ViewScripts to decorate my form elements. With radio elements, the separator can normally be overridden, but the override is being ignored when I use the ViewScript.
当我使用下面的调用和ViewScript时,单选元素由'< br/>'分隔.而不是我指定的空间.如果保留默认的装饰器,则覆盖有效.
When I use the below call and ViewScript, the radio elements are separated by a '<br />' rather than the space I've specified. If leave the default decorators, the override works.
$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:
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>
推荐答案
在视图脚本中,此行$ this-> {$ this-> element-> helper}(...)运行下面列出的功能 Zend View Helpers文档.在这种情况下,该函数为formRadio(). formRadio()的第五个参数是分隔符!通过引用元素添加第五个参数可以解决问题:
In the view script, this line, $this->{$this->element->helper}(...), runs the functions listed in the Zend View Helpers documentation. The function in this case is formRadio(). There is a fifth parameter to formRadio() which is the separator! Adding the fifth parameter, by referencing the element, solves the problem:
<span class="value"><?php echo $this->{$this->element->helper}(
$this->element->getName(),
$this->element->getValue(),
$this->element->getAttribs(),
$this->element->getMultiOptions(),
$this->element->getSeparator()
); ?></span>
这篇关于使用ViewScript装饰器时,在Zend_Form单选元素上覆盖分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!