Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1.     /**
  2.      * @Route("/{id}/edit", name="product_edit", methods={"GET","POST"})
  3.      */
  4.     public function edit(Request $request, ProductDTO $productDTO, Product $product): Response
  5.     {
  6.         $productDTO->setEntity($product);
  7.  
  8.         $form = $this->createForm(ProductType::class, $productDTO);
  9.         $form->handleRequest($request);
  10.  
  11.         if ($form->isSubmitted() && $form->isValid()) {
  12.             $entityManager = $this->getDoctrine()->getManager();
  13.             $entityManager->persist($productDTO->commit());
  14.             $entityManager->flush();
  15.  
  16.             $this->addFlash('success','Prodotto salvato con successo.');
  17.  
  18.             return $this->redirectToRoute('product_index', [
  19.                 'id' => $product->getId(),
  20.             ]);
  21.         }
  22.  
  23.         return $this->render('product/edit.html.twig', [
  24.             'product' => $productDTO,
  25.             'form' => $form->createView(),
  26.         ]);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement