我在数据库中有两个表字段 TIPOLOGY {ID,名称} EXAME {ID,名称id_tipology}
我需要创建一个按TIPOLOGY
分组的选择列表 $builder->add('select_exame', ChoiceType::class, array(
'label' => false,
'mapped' => false,
'choices' => array(
'typology_name'=>array(
'exame_name_1'=>'id_exame_1'
'exame_name_2'=>'id_exame_2'
)
'typology_name_2'=>array(
'exame_name_3'=>'id_exame_3'
)
),
)
但我找不到如何做到这一点。你能救我吗?
答案 0 :(得分:0)
实体Esame
class Esame
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nome", type="string", length=255)
*/
private $nome;
/**
* @var \AppBundle\Entity\Nome_esame
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Nome_esame")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_tipologia_esame", referencedColumnName="id")
* })
*/
private $idTipologiaEsame;
实体tipologia
class tipologiaesame
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="tipo", type="string", length=255)
*/
private $tipo;
我尝试这样做
$builder->add('select_exame', EntityType::class, array(
'label' => false,
'mapped' => false,
'class' => 'AppBundle:Esame',
'choice_label' => 'nome',
'group_by' => 'idTipologiaEsame.nome',
)
现在可行了