4

최근에 양식 및 하위 양식 작업 중입니다.동일한 유형의 여러 하위 양식 추가

나는 다음 만들었습니다

$experience->addSubForm(new Application_Form_Experience(), '0'); 
$experience->addSubForm(new Application_Form_Experience(), '1'); 

: 나는 다음과 같은 시도 할 때

$form = new Application_Form_Cv(); 
$experience = new Zend_Form_SubForm(); 
$form->addSubForm($experience, 'experience'); 

내가

$form->addSubForm($experience, 'experience');. 

에 요소 내 배열에 'experience' 감사를해야합니까 그 객체는 스스로 덮어 쓴다. 나는 오직 하나의 '경험'요소만을 얻고 0과 1은 존재하지 않는다.

array (
    'controller' => 'cv', 
    'action' => 'index', 
    'module' => 'default', 
    'CvName' => 'Cv Ingenieur informatique', 
    'LanguageCode' => 'fr', 
    'UserID' => '2', 
    'experience' => 
    array (
    'CompanyName' => 'Mondial Assistance Ltd', 
    'From' => '2002', 
    'Until' => '2009', 
    'Current' => '1', 
), 
    'submit' => 'Save CV', 
) 

Zend_Form_Subforms 만 배열에 새 키를 만듭니다.

답변

6
  1. 귀하의 하위 폼은 Zend_Form_SubForm를 확장하거나 당신이 그것을
를 복제 할 수 있도록
  • 당신은 두 번 idenentical 개체를 추가 할 수없는 행동 (끝나면 IsArray을 설정 및 제거 "형태"-decorator)의 모방해야

    다음 코드는 예상대로 작동해야합니다.

    $form = new Application_Form_Cv(); 
    $experience = new Zend_Form_SubForm(); 
    $form->addSubForm($experience, 'experience'); 
    
    $exForm = new Application_Form_Experience(); 
    $exForm->setIsArray(true); 
    $exForm->removeDecorator('form'); 
    
    $experience->addSubForm($exForm, '0'); 
    $experience->addSubForm(clone $exForm, '1'); 
    $experience->addSubForm(clone $exForm, '2'); 
    
  • 관련 문제