如何使用装饰器将多个div或fieldset添加到zend_form?

时间:2010-05-13 20:33:07

标签: php zend-framework zend-form decorator zend-decorators

我正在尝试在zend_form显示组中生成此html层次结构:

    <div class="settings">
     <div class="dashed-outline"> //want to add this div
       <fieldset disabledefaultdecorators="1" id="fieldset-settings">
          <legend>Cards</legend>
          </fieldset>
        </div>    
    </div>

这就是我目前的情况:

    <div class="settings">
       <fieldset disabledefaultdecorators="1" id="fieldset-settings">
          <legend>Cards</legend>
          </fieldset>
    </div>

这是上面的代码:

    $form->addDisplayGroup($flashcardGroup,
                           'settings',
                            array(
                                'legend' => 'Cards',
                                'disableDefaultDecorators' => true,
                                'decorators' => array(
                                                    'FormElements',
                                                    'Fieldset',
                                                     array('HtmlTag',array('tag' => 'div',  'class' => 'settings')),  
                                                    )
                                )
                            );

如何在这里添加额外的div?

1 个答案:

答案 0 :(得分:6)

如果要在Zend_Form中两次使用相同的装饰器,可以使用array(array('alias'=>'Decorator'), $options)数组语法传递setDecorators。此外,如果您传递disableDefaultDecorators选项

,则不需要使用decorators
$form->addDisplayGroup($flashcardGroup,
  'settings',
  array(
    'legend' => 'Cards',
    'decorators' => array(
      'FormElements',
      'Fieldset',
      // need to alias the HtmlTag decorator so you can use it twice
      array(array('Dashed'=>'HtmlTag'), array('tag'=>'div', 'class'=>'dashed-outline')),
      array('HtmlTag',array('tag' => 'div',  'class' => 'settings')),  
    )
  )
);