public function addToWishlistAction(Request $request, $wishlistId, $id) { $em = $this->getDoctrine()->getManager(); $user = $this->container->get('security.context')->getToken()->getUser(); $wishlist = $em->getRepository('NaissanceApplicationBundle:Wishlist')->getWishlistByWishlistIdAndUser($wishlistId, $user); $product = $em->getRepository('NaissanceApplicationBundle:Product')->find($id); if (!$wishlist || !$product) { throw $this->createNotFoundException('Unable to find entity.'); } $reference = new Reference(); $reference->setLevel(1); $reference->setWishlist($wishlist); $reference->setProduct($product); try { $em->persist($reference); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'Product added to wishlist!'); } catch (\Doctrine\DBAL\DBALException $e) { } return $this->redirect($this->generateUrl('product', array('wishlistId' => $wishlistId))); }