2016-01-21 77 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

相關問題