Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public function addAction(Request $request)
  2. {
  3. $produits_repo = $this->getDoctrine()->getRepository(Produit::class);
  4. $categorie_repo = $this->getDoctrine()->getRepository(Categorie::class);
  5. $categories = $categorie_repo->findAll();
  6. $produits = $produits_repo->findAll();
  7. if ($request->isMethod("POST"))
  8. {
  9. $produit = new Produit();
  10. $produit->setNom($request->get('nom'));
  11. $produit->setQuantite($request->get('qte'));
  12. $produit->setPrix($request->get('prix'));
  13. $produit->setCategorie($request->get('cat'));
  14. $produit->setDescription($request->get('des'));
  15. $file = $request->files->get('image');
  16. $name = $this->generateUniqueFileName().".".$file->guessExtension();
  17. $file->move(
  18. $this->getParameter("image_directory"),
  19. $name
  20. );
  21. $produit->setImage($name);
  22. $em = $this->getDoctrine()->getManager();
  23. $em->persist($produit);
  24. $em->flush();
  25. }
  26. return $this->render("@Product/Back/ajouter.html.twig",array("produits"=>$produits, "categories"=>$categories));
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement