Zend Framework 2 - Set prefix for form elements

試著忘記壹切 提交于 2019-12-25 02:52:06

问题


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

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

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?

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


回答1:


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

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();

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

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/

Martin



来源:https://stackoverflow.com/questions/15656776/zend-framework-2-set-prefix-for-form-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!