예제 #1
0
 /**
  * Creates a new Post entity.
  *
  * @Route("/new", name="post_new")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function newAction(Request $request)
 {
     $post = new Post();
     $user = $this->getUser();
     $post->setOwner($user);
     $form = $this->createForm('AppBundle\\Form\\PostType', $post);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($post);
         $em->flush();
         return $this->redirectToRoute('cabinet_index');
     }
     return ['post' => $post, 'form' => $form->createView()];
 }
예제 #2
0
 /**
  * Add post
  *
  * @param \AppBundle\Entity\Post $post
  * @return Comment
  */
 public function addPost(\AppBundle\Entity\Post $post)
 {
     $this->posts[] = $post;
     $post->setOwner($this);
     return $this;
 }