Last active
December 11, 2015 20:19
Revisions
-
frodosghost revised this gist
Jan 28, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public function updateAction(Request $request, $id) $commentForm->bind($request); if ($commentForm->isValid()) { $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('product', array('id' => $id))); -
frodosghost revised this gist
Jan 28, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,9 @@ namespace Your\Product\Bundle\Controller\ProductController; use Your\Product\Bundle\Entity\Comment; use Your\Product\Bundle\Form\CommentType; class ProductController extends Controller { /** -
frodosghost created this gist
Jan 28, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php namespace Your\Product\Bundle\Form\CommentType; use Your\Product\Bundle\Form\UserType; class CommentType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('comment', 'textarea', array( 'label' => 'Comments' )) ->add('user', new UserType(), array( 'data_class' => 'Your\Product\Bundle\Entity\User', )) ; } // .... } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ <?php namespace Your\Product\Bundle\Controller\ProductController; class ProductController extends Controller { /** * Show the Product and display the Comment form * * @Route("/{id}/product", name="product") * @Method("GET") * @Template() */ public function productAction($id) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('YourProductBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException('Unable to find Product entity.'); } $comment = new Comment; $comment->addProduct($product); $commentForm = $this->createForm(new CommentType(), $comment); return array( 'product' => $product, 'comment_form' => $commentForm->createView() ); } /** * Adds a comment to a product * * @Route("/{id}/product/comment", name="product_add_comment") * @Method("PUT") * @Template("YourProductBundle:Product:product.html.twig") */ public function updateAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('YourProductBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException('Unable to find Product entity.'); } $comment = new Comment; $comment->addProduct($product); $commentForm = $this->createForm(new CommentType(), $comment); $commentForm->bind($request); if ($commentForm->isValid()) { $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('product', array('id' => $id))); } return array( 'product' => $product, 'comment_form' => $commentForm->createView() ); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <?php namespace Your\Product\Bundle\Form\UserType; class UserType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', 'text', array( 'label' => 'Name' )) ->add('email', 'email', array( 'label' => 'Email Address' )) ; } // .... }