Zend_form渲染问题
我需要一个 zend_form ,其中主要包含复选框。我需要将它们分组并显示每个组的标题。例如
标题1
Label1 Check1
Label2 Check2
Label3 Check3
标题2
Label4 Check4
Label5 Check5
Label6 Check6
首先我不知道如何显示标题(“标题”)!有没有一种方法可以将标签添加到表单而不是元素或任何其他解决方案来在 Zend Form 中添加这些标题?
其次我该如何呈现这种方式?我应该使用什么样的装饰器? 我对装饰器有些了解,但我不太了解?
有人有什么想法吗? 谢谢!
I need a zend_form which will contain mostly checkboxes. I need to group them and also display a title for each group. e.g.
Heading 1
Label1 Check1
Label2 Check2
Label3 Check3
Heading 2
Label4 Check4
Label5 Check5
Label6 Check6
First I don't know how to display the title ("headings")! Is there a way that you can add a label to a form bu not to an element or any other solution to add these titles in Zend Form?
Second how do I render this way? what kind of decorator should I use?
I red something about decorators but I did not understand much of it?
Anybody any Idea?
thanx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能对手册的这一部分感兴趣,这似乎正是您想要获得的内容:23.4.3。显示组 (引用):
这应该允许您将表单元素重新分组到字段集中,并且每个元素都可以有其图例 - 在您的情况下,这将是“标题 X”。
将复选框添加到表单后,您应该能够使用以下内容重新分组它们:
对于渲染部分,我想它将使用
Zend_Form_Decorator_Fieldset
在评论后编辑
要设置每个组的标题,您必须设置其“
图例
”,并将其作为选项传递。例如,这是我从很久以前从事的一个旧项目中找到的一段代码:
“Meta-données”,据我所知,是“
legend< /code>”用于包含这些元素的字段集。
You might be interested by this section of the manual, which seems to be exactly about what you want to obtain : 23.4.3. Display Groups (quoting) :
This should allow you to have your form elements re-grouped in fieldsets, and each one of those can have its legend -- in your case, that would be "heading X".
Once your checkboxes have been added to the form, you should be able to re-group them by using something like this :
For the rendering part, I suppose it'll use
Zend_Form_Decorator_Fieldset
Edit after the comment
To set the title of each group, you have to set its "
legend
", passing that as an option.For example, here is a piece of code I found from an old project I worked on quite some time ago :
The "Meta-données", from what I recall, is the "
legend
" used for the fieldset containing those elements.尝试将此类添加
到 /Your/Own/Form/Element 目录,例如,
您可以添加“注释”元素类型,该类型仅显示标题等静态文本。例如
try adding this class
to /Your/Own/Form/Element directory eg
You can then add 'note' element types which just display static text like your headings. eg