翻译自:https://stackoverflow.com/questions/2148510
7568 次
1

私はViewScriptsを使用してフォーム要素を装飾しています。ラジオ要素では、通常、セパレータをオーバーライドできますが、ViewScriptを使用すると、オーバーライドは無視されます。

以下の呼び出しと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>
4

3 に答える 3

7

ビュースクリプトでは、この行$ this-> {$ this-> element-> helper}(...)は、ZendViewHelpersのドキュメントにリストされている関数を実行します。この場合の関数はformRadio()です。セパレータであるformRadio()には5番目のパラメータがあります!要素を参照して5番目のパラメーターを追加すると、問題が解決します。

<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>
于 2010-01-28T20:26:48.380 に答える
6

私はこの問題を抱えていました。disableLoadDefaultDecoratorsをに設定しtrue、separatorをに設定する&nbsp;か、必要なものを使用することで解決しました。

$form->addElement('multiCheckbox', 'myFields', array(
    'disableLoadDefaultDecorators' => true
    ,'separator'    => '&nbsp;'
    ,'multiOptions' => array(
        'title'       => 'Title'
        ,'first_name' => 'First Name'
        ,'surname'    => 'Surname'
    )
    ,'decorators'   => array(
        'ViewHelper'
        ,'Errors'
        ,array('HtmlTag', array('tag' => 'p'))          
    )
));
于 2010-06-01T09:56:32.473 に答える
2

実際には、1行で実行できます。

echo $this->element->setSeparator('&nbsp;');
于 2013-07-19T22:42:52.720 に答える