Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 子窗体中的子窗体_Zend Framework_Zend Form_Zend Form Sub Form - Fatal编程技术网

Zend framework 子窗体中的子窗体

Zend framework 子窗体中的子窗体,zend-framework,zend-form,zend-form-sub-form,Zend Framework,Zend Form,Zend Form Sub Form,我正在使用Zend表单制作一个模型。我有一个子表单,名为$product\U item。我想将它的多个实例添加到另一个名为$items的子窗体中。我该怎么做呢?我并不觉得Zend参考指南特别有用。您可以将子表单添加到子表单中:- $form = new Application_Form_Test(); $subForm1 = new Application_Form_TestSubForm(); $subForm2 = new Application_Form_TestSubForm(); $s

我正在使用Zend表单制作一个模型。我有一个子表单,名为$product\U item。我想将它的多个实例添加到另一个名为$items的子窗体中。我该怎么做呢?我并不觉得Zend参考指南特别有用。

您可以将子表单添加到子表单中:-

$form = new Application_Form_Test();
$subForm1 = new Application_Form_TestSubForm();
$subForm2 = new Application_Form_TestSubForm();
$subForm1->addSubForm($subForm2, 'sub2');
$form->addSubForm($subForm1, 'sub1');
$this->view->form = $form;
提交时,子表单值将在
$\u POST
数组中的数组中可用<例如,代码>$value=$\u POST['sub1']['sub2']['name']

要打印或访问子窗体中的元素,您有几个选项:-

如果
$subForm1
有这样声明的元素:-

$email = new Zend_Form_Element_Text('email');
然后,可以在视图中呈现
电子邮件
字段,如下所示:-

<?php echo $this->element->sub1->email; ?>

谢谢如果可以的话,我会跟进。。。我知道您可以在视图中打印普通表单元素,如下所示:
。如果$email是$subForm1的一个元素,您将如何打印它?更新:计算出:
$this->element->sub1->sub2->email
<?php
    $form = $this->element;
    $formElements = $form->getElements();
?>