Symfony 2 - 表单实体类型:如何格式化生成的下拉列表? [英] Symfony 2 - Form Entity Type: How to format the generated drop-down?
问题描述
我有一个表单,其中显示了可供选择的类别下拉菜单.
I have a form that shows a drop-down menu of categories to choose from.
这些类别是使用 Gedmo 树扩展设置的,因此一个类别可以有子类别.
These categories are setup using the Gedmo Tree Extension, so a category can have child categories.
我在表单构建器中有一个自定义查询,它只选择属于特定组的类别.但是,我需要能够在下拉列表中显示哪些类别是父母,哪些是孩子,例如
I have a custom query in the form builder that selects only the categories that belong to a specific group. However, I need to be able to show in the drop-down which categories are parents and which are children, e.g.
Parent Category 1
-- Child Category A
-- Child Category B
Parent Category2
-- Child Category C
知道如何实现这一目标吗?
Any idea how I can achieve this?
另外,如何将变量从调用 formtype 的控制器传递给我的 query_builder?
Also, how can I pass a variable to my query_builder, from the controller that is calling the formtype?
推荐答案
几天前,我希望完成完全相同的事情!我在这里使用了 Neurofr 解决方案:Symfony2,Doctrine Extensions Tree : 生成一个 "树"状下拉选择列表
A few days ago I was looking to accomplish exactly the same thing ! I used Neurofr solution here : Symfony2,Doctrine Extensions Tree : Generating a "tree"-like dropdown Select list
这是工作.现在我将尝试停用从树中获得最后一个孩子的所有选项.
And it's work. Now I will try to deactivate all options that got last children from the tree.
这篇关于Symfony 2 - 表单实体类型:如何格式化生成的下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!