Symfony2 - Set a selected value for the entity field

前端 未结 4 680
忘了有多久
忘了有多久 2020-12-20 14:59

I\'m trying to set a selected value inside an entity field. In accordance with many discussions I\'ve seen about this topic, I tried to set the data option but

4条回答
  •  情书的邮戳
    2020-12-20 15:26

    In order to option appear selected in the form, you should set corresponding value to entity itself.

    $place = $repository->find(2);
    $entity->setPlace($place);
    $form = $this->createForm(new SomeFormType(), $entity);
    ....
    

提交回复
热议问题