如何配置 Zend_Form 以使用数组表示法?

我在配置 Zend_Form 时遇到困难.我有一个 Zend_Form 子类.该表格包含一些必需信息和一些附加信息.我希望可以通过数组访问附加信息.提交的数据看起来像这样:

I'm having difficulty configuring Zend_Form. I have a Zend_Form sub-class. The form has some required information and some additional information. I want the additional information to be accessible via an array. The submitted data will look something like this:

$formData['required1']
$formData['required2']
$formData['addiotnalData']['aData1']
$formData['addiotnalData']['aData2']

我在谷歌上搜索并尝试了我找到的所有建议(使用 subForms 并设置 Zend_Form::setIsArray($flag)Zend_Form::setElementsBelongTo($array) 方法),但还没有想出如何做到这一点.

I've Googled this and tried all the suggestions I've found (using subForms and setting the Zend_Form::setIsArray($flag) and Zend_Form::setElementsBelongTo($array) methods), but have not figured out how to do this.

我做错了什么?如何设置表单元素的名称,以便我可以使用数组表示法访问数据?

What am I doing wrong? How do I set the names of form elements so that I can access the data with array notation?

推荐答案

已排序!问题是正在使用的自定义装饰器.

Sorted it! The problem is a custom decorator that was being used.

//In
$subForm = new Form_SubForm(); //this can be a Zend_Form or Zend_Form_SubForm     
$subForm->setIsArray(true);
$this->addSubForm($subForm, 'subform');

元素将以 subform-elementname 的 id 和 subform[elementname] 的名称呈现.

Elements will be rendered with a id of subform-elementname and a name of subform[elementname].

相关文章