Zend - 将subForm添加到现有显示组

时间:2011-05-06 05:41:42

标签: zend-framework zend-form

在我的控制器中,我得到了一个如下所示的函数:

public function newExperienceAction() {
        $this->_helper->layout->disableLayout();
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('newExperience', 'html')->initContext();

        $id = $this->_getParam('id', null);

        $this->form = new Application_Form_Cv();
        $this->experience = new Zend_Form_SubForm();
        $this->form->addSubForm($this->experience, 'experience');
        $rowExperience = new Application_Form_Experience();
        $rowExperience->setDisplayGroups('experience');
        $this->experience->addSubForm($rowExperience, "experience$id", $id+3);

        echo $rowExperience->__toString();
    }

当用户在表单上按(+)时,将显示一个新的子窗体。

我现在正在将其塑造成一张桌子。我将在此表单上有多个subForm,因此我需要使用DisplayGroups。

在这种情况下,我认为我必须在首次创建表单时创建一个显示组。

然后我需要将新的子表单附加到现有的显示组。

所以问题是:

如何将新的子表单添加到现有的显示组?

2 个答案:

答案 0 :(得分:1)

我担心现在不可能。我正在使用Zend Framework版本1.11.7,addDisplayGroup方法的代码如下所示:

foreach ($elements as $element) {
    if($element instanceof Zend_Form_Element) {
         (...)
    }

    if (isset($this->_elements[$element])) {
        (...)
    }
}

所以这还不支持。您只能添加Zend_Form_Element个实例

答案 1 :(得分:1)

您只需添加

即可实现此目的
$rowExperience->setIsArray(true);

这会使子表单像显示组一样工作,即它的值被包装在由子表单的名称(在您的情况下为experience$id)索引的数组中。

相关问题