Zend Framework 2-为表单元素设置前缀 [英] Zend Framework 2 - Set prefix for form elements

查看:72
本文介绍了Zend Framework 2-为表单元素设置前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为某种形式的每个元素添加前缀的方法.

I'm looking for a way to add prefixes for every element of a certain form.

如果找到这篇文章告诉我,有一个elementsBelongTo选项可用于实现我想要的功能

If found this post telling me that there is a elementsBelongTo option which I can use to achieve what I want.

很遗憾,我找不到任何解释用法的文档.有谁知道我该如何使用该选项?如果它仍在ZF2中?

Unfortunately I can't find any documentation explaining the usage. Does anyone know how I can use this option? And if it's still in ZF2?

还有:我有办法将它与漂亮的AnnotationForms组合吗?

And furthermore: I there a way to combine it with the nice AnnotationForms?

推荐答案

不知道它是否有帮助,但是除了前缀,您还可以使用表单/字段集名称将元素包装在表单或字段集中.

Don't know if it will help, but instead of prefix you can wrap elements in form or fieldset with form/fieldset name.

您只需要拥有一个表单名称或进行设置,然后使用setWrapElements

You just need to have a name of form or set it and then use setWrapElements

$form->setName('some_name');
$form->setWrapElements(true);
$form->prepare();

从这一点开始,元素的全名,例如'password'将为"some_name ['password']"

from this point full name of element, for example 'password' will be "some_name['password']"

如果使用注释,则可以将其与ComposedObject结合使用. 很好的解释如下: http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/

If you are using annotations you can use this with combination of ComposedObject. It's very good explained here: http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/

马丁

这篇关于Zend Framework 2-为表单元素设置前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆