Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 使用ViewScript装饰器时覆盖Zend_表单单选元素上的分隔符_Zend Framework_Zend Form_Zend View_Zend Form Element_Zend Decorators - Fatal编程技术网

Zend framework 使用ViewScript装饰器时覆盖Zend_表单单选元素上的分隔符

Zend framework 使用ViewScript装饰器时覆盖Zend_表单单选元素上的分隔符,zend-framework,zend-form,zend-view,zend-form-element,zend-decorators,Zend Framework,Zend Form,Zend View,Zend Form Element,Zend Decorators,我正在使用ViewScripts来装饰我的表单元素。使用单选元素时,通常可以覆盖分隔符,但在使用ViewScript时会忽略该覆盖 当我使用下面的调用和ViewScript时,单选元素之间用“”分隔,而不是用我指定的空格分隔。如果保留默认装饰符,则覆盖将起作用 $this->addElement('radio', 'active', array( 'disableLoadDefaultDecorators' => true, 'decorators' => ar

我正在使用ViewScripts来装饰我的表单元素。使用单选元素时,通常可以覆盖分隔符,但在使用ViewScript时会忽略该覆盖

当我使用下面的调用和ViewScript时,单选元素之间用“
”分隔,而不是用我指定的空格分隔。如果保留默认装饰符,则覆盖将起作用

$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(),
));
视图脚本:

<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}(…)运行中列出的函数。本例中的函数是formRadio()。formRadio()还有第五个参数,它是分隔符!通过引用元素添加第五个参数,可以解决以下问题:

<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>

在视图脚本中,这一行$this->{$this->element->helper}(…)运行中列出的函数。本例中的函数是formRadio()。formRadio()还有第五个参数,它是分隔符!通过引用元素添加第五个参数,可以解决以下问题:

<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>

我遇到了这个问题,我通过将disableLoadDefaultDecorators设置为
true
并将separator设置为
或任何您需要的设置来解决这个问题

$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'))          
    )
));

我曾经遇到过这个问题,我通过将disableLoadDefaultDecorators设置为
true
并将separator设置为
或任何您需要的设置来解决这个问题

$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'))          
    )
));

实际上,它可以在一行中完成:

echo $this->element->setSeparator('&nbsp;');

实际上,它可以在一行中完成:

echo $this->element->setSeparator('&nbsp;');

您的解决方案适用于您的情况,但在使用视图脚本时不起作用。不过,感谢您发布它,对于其他试图找到解决方案的人来说,它可能会派上用场。您的解决方案适用于您的情况,但在使用视图脚本时不会起作用。不过,感谢您发布它,它可能会为其他试图找到解决方案的人带来方便。这是设置分隔符的方法,如果您使用的是标准装饰器,它会起作用。我有一个ViewScript装饰程序,它忽略了设置。如果你看一下我的解决方案,你就会知道我是如何解决这个问题的。这是设置分隔符的方法,如果你使用标准的装饰器,它是有效的。我有一个ViewScript装饰程序,它忽略了设置。如果你看看我的解决方案,你就会知道我是如何解决这个问题的。