1

ViewScript를 사용하여 양식 요소를 꾸미고 있습니다. 라디오 요소를 사용하면 일반적으로 구분 기호를 재정의 할 수 있지만 ViewScript를 사용하면 대체가 무시됩니다.ViewScript Decorator를 사용할 때 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> 

답변

7

,이 라인, $이 -> {$ this-> 엘리먼트 -> 도우미} (...)는에 열거 된 기능을 실행 Zend View Helpers documentation. 이 경우 함수는 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> 
6

, 내가 &nbsp;true과 분리 설정을 disableLoadDefaultDecorators를 사용하여 해결 한 또는 이제까지 당신이 필요 요소를 참조하여, 다섯 번째 매개 변수를 추가하여 문제를 해결합니다.

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

귀하의 솔루션은 상황에 작동하지만, 뷰 스크립트를 사용하는 경우 근무하지 않을 것입니다. 게시 해 주셔서 감사합니다. 다른 사람이 솔루션을 찾으려고 할 때 유용 할 수 있습니다. – Sonny

2

사실, 그것은 하나 개의 라인으로 수행 할 수 있습니다

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

그건 분리 기호를 설정하는 방법이고, 표준 장식자를 사용한다면 작동합니다. 설정을 무시하고있는 ViewScript 데코레이터가 있습니다. 내 솔루션을 보면 문제를 어떻게 해결했는지 알 수 있습니다. – Sonny

관련 문제