2016-01-21 36 views
0

你可以在这里看到我的FormType。 我想让出现一个下拉菜单,其中学生姓名为值,ID为密钥。如何在FormType中的“eleve”中获得id和名称?

像这样:

- >加( 'eleve', '选择',阵列( '选择'=>数组(瞳孔的ID =>光瞳)的名称,

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('eleve', 'entity', array(
      'class' => 'WCSCantineBundle:Eleve' 
     )) 
     ->add('status', 'choice', array(
      'choices' => array('0' => 'Non-Inscrit'), 
      'label' => false 
      )) 
     ->add('date', 'text', array(
      'label' => false 
     )) 
     ->add('Ajouter', 'submit'); 
} 

谢谢您的帮助。

回答

0
->add('eleve', 'entity', array(
      'class' => 'WCSCantineBundle:Eleve' 
      'choice_label' => 'pupilname', 
     )) 

这里学生的名字将在你的Eleve实体

是字段的名称

这将创建一个下拉菜单,从数据库加载,在提交所有Eleve记录的选择的ID将通过形式

Read more here

+0

谢谢你的人提交! 而我错过了我的实体中的__toString()方法以使其工作。我会尝试。 –

+0

谢谢!这十分完美!!! :D –

+0

因为它适合你,考虑点击接受答案刻度标记,这将帮助我;) – Dheeraj

相关问题