Symfony 2 - 重新排列表单域 [英] Symfony 2 - rearrange form fields
问题描述
在我们的 Symfony2 项目中,对于带有嵌入表单的表单,我们有一个非常复杂的结构......现在我们需要以特定顺序输出表单.
In our Symfony2 project we have a very complex structure for forms with embedded forms.... Now we got the requirement to bring the output of the form in an specific order.
这里是问题所在:我们使用 form_widget(form),现在我们正在寻找对象中的解决方案(例如通过注释)或表单构建器将特定字段移动到表单的末尾.在 symfony 1.4 中它是 widget-movefield() 函数,我猜...
And here is the problem: We use the form_widget(form) and now we are looking for a solution in the object (e.g. via annotations) or the formbuilder to move a specific field to the end of the form. in symfony 1.4 it was the widget-movefield() function, i guess...
谢谢...
推荐答案
您可以使用此包对字段重新排序:https://github.com/egeloen/IvoryOrderedFormBundle
You can re-order the fields using this bundle: https://github.com/egeloen/IvoryOrderedFormBundle
这允许你做这样的事情:
This allows you to do things like this:
$builder
->add('g', 'text', array('position' => 'last'))
->add('a', 'text', array('position' => 'first'))
->add('c', 'text')
->add('f', 'text')
->add('e', 'text', array('position' => array('before' => 'f')))
->add('d', 'text', array('position' => array('after' => 'c')))
->add('b', 'text', array('position' => 'first'));
这将在核心中,但被拒绝并被拉入一个包中.
This was going to be in core, but was rejected and pulled out into a bundle.
这篇关于Symfony 2 - 重新排列表单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!