嵌入式表单的持久性

时间:2017-03-13 21:51:05

标签: php forms symfony doctrine-orm symfony-3.2

我有2个实体EnchereProduit,分别有2个Form

在我的Enchere表格中,有:

public function buildForm(FormBuilderInterface $builder, array $options)
{
   $builder->add('idProduit', ProduitType::class); //Produit's Form
}

idProduitEnchereProduit之间的关系ManyToOne:

/**
 * @var \LP\EnchereBundle\Entity\Produit
 *
 * @ORM\ManyToOne(targetEntity="LP\EnchereBundle\Entity\Produit"
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id_produit", referencedColumnName="id")
 * })
 */
private $idProduit;

在我的控制器中,我想用两种形式冲洗2个水合物... 我该怎么做?

在添加我的嵌入表单之前,我的控制器是:

public function addAction(Request $request){

  $enchere = new Enchere();



  $form = $this->get('form.factory')->create(EnchereType::class, $enchere);

  if($request->isMethod('POST')  &&  $form->handleRequest($request)->isValid()) {


      $em = $this->getDoctrine()->getManager();
      $em->persist($enchere);
      // !!! Here I want to persist an Produit's object !!!
      $em->flush();

      $request->getSession()->getFlashBag()->add('notice', 'OK !');

      return $this->redirectToRoute('lp_enchere_view', array('id' => $enchere->getId()));
    }




  return $this->render('LPEnchereBundle:Advert:addEnchere.html.twig', array(
    'form' => $form->createView(),
    ));
}

0 个答案:

没有答案