如何配置 Zend_Form 使用数组表示法?
我在配置 Zend_Form 时遇到困难。我有一个 Zend_Form 子类。该表格包含一些必需信息和一些附加信息。我希望可以通过数组访问附加信息。提交的数据将如下所示:
$formData['required1']
$formData['required2']
$formData['addiotnalData']['aData1']
$formData['addiotnalData']['aData2']
我已经在 Google 上搜索了此内容并尝试了我找到的所有建议(使用 subForms 并设置 Zend_Form::setIsArray($flag)
和 Zend_Form: :setElementsBelongTo($array)
方法),但还没有弄清楚如何做到这一点。
我做错了什么?如何设置表单元素的名称,以便可以使用数组表示法访问数据?
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']
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
排序了!问题是正在使用的自定义装饰器。
元素将使用 id
subform-elementname
和名称subform[elementname]
进行渲染。Sorted it! The problem is a custom decorator that was being used.
Elements will be rendered with a id of
subform-elementname
and a name ofsubform[elementname]
.扩展答案,因为 $form->setIsArray(TRUE) 不适用于我的元素自定义装饰器。渲染 Zend_Form_Element 需要我的自定义 ViewScript 装饰器。
问题是,它使用 $this->element->getName() 渲染元素名称。我必须在 ViewScript 装饰器脚本中使用 $this->element->getFullyQualifiedName() 。
To expand on the answer because $form->setIsArray(TRUE) was not working with my custom decorator for elements. My custom ViewScript decorator was needed for rendering the Zend_Form_Element.
The problem, it was rendering the element name with $this->element->getName(). I had to use $this->element->getFullyQualifiedName() in the ViewScript decorator script.