Symfony2 Data Transformer on hidden field

后端 未结 2 1571
死守一世寂寞
死守一世寂寞 2021-02-02 04:34

I\'ve searched and not found anyone with this problem.

I\'ve created my own Data Transformer as set out in the Cookbook and it all seems right but i get the error:

2条回答
  •  梦如初夏
    2021-02-02 05:20

    I just created an input type hidden:

    $builder->add('child_id', 'hidden', array('mapped' => false))
    

    In the newAction I did fill with the parent id:

    $childForm->get('parent_id')->setData($parentEntity->getId());
    

    And finally in createAction I did put:

    $child->setParent($em->getReference('MyBundle:Parent', $form["child_id"]->getData()))
    

    PS: I understand that you wanted to create your Data Transformer, but if your problem is persist object with parent id, it will help you.

提交回复
热议问题