Zend Form在显示组中添加元素数组

时间:2013-08-27 15:49:48

标签: zend-form

这里我设置的文本框数组属于一个。

$this->addElement('text', '1', array(
        'label'   => 'Text One',
        'belongsTo' => 'txtarray'
    ));

    $this->addElement('text', '2', array(
        'label'   => 'Text Two',
        'belongsTo' => 'txtarray'
    ));

    $this->addElement('text', '3', array(
        'label'   => 'Text Three',
        'belongsTo' => 'txtarray'
    ));

我想将这些全部添加到一个显示组

$this->addDisplayGroup(array('txtarray'), 'pcinfo', array('legend' => 'Other Block'));

但这不起作用。 如何将数组元素组添加到显示组?

1 个答案:

答案 0 :(得分:1)

试试这个:

$this->addElement('text', '1', array(
    'label'   => 'Text One',
));

$this->addElement('text', '2', array(
    'label'   => 'Text Two',
));

$this->addElement('text', '3', array(
    'label'   => 'Text Three',
));

然后:

$this->addDisplayGroup(array('1','2','3'), 'pcinfo', array('disableLoadDefaultDecorators' => true,'legend' => 'Other Block')); 

不要忘记添加这些行:

$this->setDisplayGroupDecorators(array(
        'FormElements',
        'Fieldset'
    ));

您可以访问此博客,您将获得很大帮助 http://zendgeek.blogspot.in/2009/07/zend-form-display-groups-decorators.html