Inject Symfony EntityManager into Form Type via Services

后端 未结 3 1260
心在旅途
心在旅途 2021-01-13 21:59

I need to modify some fields in my form (label and class), based on whether the entity is the latest published version or not. So I need to be able to inject the entity mana

3条回答
  •  爱一瞬间的悲伤
    2021-01-13 22:13

    You created a new ViewType without passing the EntityManager. Get the form type from the dic with

    $form = $this->createForm($this->get('gutensite_cms.form.type.view'), $view);
    

    or create a new object with the entity manager as an argument

    $form = $this->createForm(new ViewType($this->getDoctrine()->getManager()), $view);
    

提交回复
热议问题