Symfony表单类别

编程入门 行业动态 更新时间:2024-10-28 05:28:04
本文介绍了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 ?

感谢您的帮助;)

推荐答案

要为类别创建 tree 结构,可以使用 StofDoctrineExtensionsBundle

To make tree structure for your categories you can use StofDoctrineExtensionsBundle

该软件包的文档在这里

您需要使用 Tree 扩展名(嵌套集变体).

You would need to use Tree extension (nestedset variation).

以下是显示如何为项目添加类别

更多推荐

Symfony表单类别

本文发布于:2023-10-10 22:56:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   类别   Symfony

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!