Пример #1
0
 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));
 }
Пример #2
0
 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());
 }