Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addAction(Request $request)
- {
- $produits_repo = $this->getDoctrine()->getRepository(Produit::class);
- $categorie_repo = $this->getDoctrine()->getRepository(Categorie::class);
- $categories = $categorie_repo->findAll();
- $produits = $produits_repo->findAll();
- if ($request->isMethod("POST"))
- {
- $produit = new Produit();
- $produit->setNom($request->get('nom'));
- $produit->setQuantite($request->get('qte'));
- $produit->setPrix($request->get('prix'));
- $produit->setCategorie($request->get('cat'));
- $produit->setDescription($request->get('des'));
- $file = $request->files->get('image');
- $name = $this->generateUniqueFileName().".".$file->guessExtension();
- $file->move(
- $this->getParameter("image_directory"),
- $name
- );
- $produit->setImage($name);
- $em = $this->getDoctrine()->getManager();
- $em->persist($produit);
- $em->flush();
- }
- return $this->render("@Product/Back/ajouter.html.twig",array("produits"=>$produits, "categories"=>$categories));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement