Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 10th, 2011  |  syntax: PHP  |  size: 1.88 KB  |  views: 170  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2. * Article controller.
  3. *
  4. * @Route("/article")
  5. */
  6. class ArticleController extends Controller
  7. {
  8.     /**
  9.      * Displays a form for the article Assistant.
  10.      *
  11.      * @Route("/assistant", name="article_assistant")
  12.      * @Template()
  13.      */
  14.     public function articleAssistantAction()
  15.     {
  16.        $article = new Article();
  17.        
  18.        $product = new Product();
  19.        $article->setProduct($product);
  20.        
  21.        $productVariantAssociation = new ProductVariantAssociation();
  22.        $product->getProductVariantAssociation()->add($productVariantAssociation);
  23.              
  24.        $form = $this->createForm(new ArticleType(), $article);
  25.        
  26.         return array(
  27.            'article' => $article,
  28.           'form'   => $form->createView(),
  29.        );
  30.     }
  31.    
  32.     /**
  33.     * Creates a new Article entity.
  34.     *
  35.     * @Route("/assistant/create", name="article_assistant_create")
  36.     * @Method("post")
  37.     * @Template()
  38.     */
  39.     public function articleAssistantCreateAction()
  40.     {
  41.        $article = new Article();
  42.        
  43.        $product = new Product();
  44.        $article->setProduct($product);
  45.        
  46.        $variant = new Variant();
  47.        $productVariantAssociation = new ProductVariantAssociation();
  48.        $productVariantAssociation->setVariant($variant);
  49.        $productVariantAssociation->setProduct($product);
  50.        $product->getProductVariantAssociation()->add($productVariantAssociation);
  51.        
  52.        $request = $this->getRequest();
  53.        $form    = $this->createForm(new ArticleType(), $article);
  54.        $form->bindRequest($request);
  55.  
  56.        $em = $this->getDoctrine()->getEntityManager();
  57.        $em->persist($article);
  58.        $em->persist($product);
  59.        $em->persist($variant);
  60.        $em->persist($productVariantAssociation);
  61.        $em->flush();
  62.        
  63.        return array(
  64.           'article' => $article
  65.        );
  66.     }
  67. }
  68.