How to set up default value in symfony2 select box with data from database

后端 未结 2 1912
清歌不尽
清歌不尽 2020-12-18 16:32

I have this code

->add(\'user\', \'entity\', array(
                            \'class\' => \'Acme\\Entity\\User\',
                            \'quer         


        
2条回答
  •  梦毁少年i
    2020-12-18 17:09

    You can use the one of the following:

    1. Set a default value in the object

      $cl->setUser($this->getDoctrine()->getEntityManager()->getReference('Acme:User',2));
      
    2. Use a preferred choices option in the form builder:

      'preferred_choices' => array('2')
      
    3. Or set 'property_path' => false and use a 'data' => YourDefaultEnity

提交回复
热议问题