Пример #1
0
 /**
  * Creates a new Photo entity.
  */
 public function createAction(Request $request, $id)
 {
     if (!$this->container->getParameter('manhattan_posts.include_attachments')) {
         throw new AccessDeniedHttpException('Attachment functionality has not been enabled in the bundle.');
     }
     if (false === $this->get('security.context')->isGranted('ROLE_USER')) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $post = $em->getRepository('ManhattanPostsBundle:Post')->findOneById($id);
     if (!$post) {
         throw $this->createNotFoundException('Unable to find Post entity.');
     }
     $document = new Attachment();
     $document->addPost($post);
     $form = $this->createForm(new AttachmentType(), $document);
     $form->bind($request);
     if ($form->isValid()) {
         $em->persist($document);
         $em->flush();
         return $this->redirect($this->generateUrl('console_news_documents', array('id' => $post->getId())));
     }
     return $this->render('ManhattanPostsBundle:Document:documents.html.twig', array('entity' => $post, 'form' => $form->createView()));
 }
Пример #2
0
 /**
  * Add Attachment
  *
  * @param Manhattan\Bundle\PostsBundle\Entity\Attachment $attachment
  */
 public function addAttachment(Attachment $attachment)
 {
     $attachment->addPost($this);
     $this->attachments[] = $attachment;
     return $this;
 }