예제 #1
0
 public function createAction()
 {
     $product = new Product();
     $product->setName('A Foo Bar');
     $product->setPrice('19.99');
     $dm = $this->get('doctrine_mongodb')->getManager();
     $dm->persist($product);
     $dm->flush();
     return $this->render('AcmeStoreBundle:Default:create.html.twig', array('product' => $product));
 }
 /**
  * @Route("/product/create", name="products_create", )
  */
 public function createAction(Request $request)
 {
     $product = new Product();
     // dummy code - this is here just so that the Task has some tags
     // otherwise, this isn't an interesting example
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $product->addTag($tag1);
     $tag2 = new Tag();
     $tag2->setName('tag12');
     $product->addTag($tag2);
     $product->setName('test');
     $product->setPrice(2.5);
     $dm = $this->get('doctrine_mongodb')->getManager();
     $dm->persist($product);
     $dm->flush();
     // end dummy code
     $form = $this->createForm(ProductForm::class, $product);
     $form->handleRequest($request);
     if ($form->isValid()) {
         // ... maybe do some form processing, like saving the Task and Tag objects
         $dm = $this->get('doctrine_mongodb')->getManager();
         $dm->persist($product);
         $dm->flush();
         $this->addFlash('success', 'product inserted');
         return $this->redirectToRoute('products_list', array());
     }
     return $this->render('AcmeStoreBundle:product:new.html.twig', array('form' => $form->createView()));
 }