Symfony表单类别-子类别 [英] Symfony form category - subcategory
本文介绍了Symfony表单类别-子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试制作一个带有类别和子类别的表单,如下图所示:
I try to make a form with category and subcategory like the picture below :
所以,我把表格做成了:
So, I made my form like that :
->add('souscategorie', EntityType::class, array(
'label' => false,
'class' => 'App:souscategorie',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('souscategorie')
->leftJoin('souscategorie.categorie', 'categorie')
->addSelect('souscategorie')
->addSelect('categorie')
;
},
'expanded'=> true,
'multiple'=> true,
'choice_label' => function($sousCategorie){
return $sousCategorie->getCategorie()->getNom()." - ".$sousCategorie->getNom();
},
'group_by' => function($sousCategorie, $key, $value){
return $sousCategorie->getCategorie()->getNom();
}))
结果显示所有类别和子类别是串联的.
The result show all categories and subcategories concatenate.
如何划分类别和子类别?
How to split categories and subcategories ?
感谢您的帮助;)
推荐答案
To make tree
structure for your categories
you can use StofDoctrineExtensionsBundle
该软件包的文档在这里
您需要使用 Tree
扩展名(嵌套集变体).
You would need to use Tree
extension (nestedset variation).
以下是显示 查看全文