我最近正在处理表单和子表单。
我创建了以下内容:
$form = new Application_Form_Cv();
$experience = new Zend_Form_SubForm();
$form->addSubForm($experience, 'experience');
由于
,我的数组中确实有一个元素'experience'
$form->addSubForm($experience, 'experience');.
当我尝试以下操作时:
$experience->addSubForm(new Application_Form_Experience(), '0');
$experience->addSubForm(new Application_Form_Experience(), '1');
对象会覆盖自身,我只获得一个'体验'元素,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
在数组中创建新密钥?
答案 0 :(得分:6)
以下剪辑应按预期工作
$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');