public function createProductAction() { $category = new Category(); $category->setName("Rowery"); $product = new Product(); $product->setName("Rower biegowy"); $product->setPrice(230.44); $product->setDescription("opis rowerka"); $product->setCategory($category); $em = $this->getDoctrine()->getManager(); $em->persist($category); $em->persist($product); $em->flush(); return $this->render("AcmeStoreBundle:Default:Product.html.twig", array("product" => $product)); }
public function createProductAction() { $category = new Category(); $category->setName('Main Products ' . rand(1, 100)); $product = new Product(); $product->setName('Foo ' . rand(101, 200)); $product->setPrice(19.99); $product->setDescription('Foo desc'); // relate this product to the category $product->setCategory($category); $em = $this->getDoctrine()->getManager(); $em->persist($category); $em->persist($product); $em->flush(); return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId()); }
/** * Creates a form to delete a Category entity. * * @param Category $category The Category entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Category $category) { return $this->createFormBuilder()->setAction($this->generateUrl('category_delete', array('id' => $category->getId())))->setMethod('DELETE')->getForm(); }