2010-02-03 25 views

回答

1

您可以使用子窗體。 Zend_FormZend_Form_SubForm之間的唯一區別是裝飾:

$form1 = new Zend_Form(); 
// ... add elements to $form1 
$form2 = new Zend_Form(); 
// ... add elements to $form2 

/* Tricky part: 
* Have a look at Zend_Form_SubForm and see what decorators it uses. 
*/ 
$form1->setDecorators(array(/* the decorators you've seen */)); 
$form2->setDecorators(array(/* ... */)); 

$combinedForm = new Zend_Form(); 
$combinedForm->addSubForm('form_1', $form1); 
$combinedForm->addSubForm('form_2', $form2); 

然後在控制器分配形式的觀點:

$this->view->form = $combinedForm; 

你可以存取權限由名稱視圖中的兩個子表單:

// In the view 
echo $this->form->form_1; 
echo $this->form->form_2; 
+0

在我看來,我將如何訪問表單元素? $這個 - >表 - > ...? – Andrew 2010-02-03 18:54:02

+0

getSubForm('subformName')? – takeshin 2010-02-03 19:00:41

3

以下是我終於實現了......我不想每個命名空間的形式,我只是想在表單中的所有元素,所以我決定只廣告d單獨使用所有元素,而不使用子表單。

<?php 

class Form_DuplicateUser extends Zend_Form 
{ 
    public function init() 
    { 
     $this->setMethod('post'); 

     $form1 = new Form_ContactPrimaryInformationForm(); 
     $this->addElements($form1->getElements()); 

     $form2 = new Form_ContactAdditionalInformationForm(); 
     $this->addElements($form2->getElements()); 
    } 
} 
+0

+1這也是我的做法。 – 2010-11-15 18:39:16