Ejemplo n.º 1
0
 /**
  * Allow the user to view the article using the $id to find the article, create a form for submitting the
  * comments linked to the article.
  *
  * @param Request $request
  * @param $id
  *
  * @return \Symfony\Component\Form\Form|\Symfony\Component\Form\FormInterface
  */
 public function viewArticle(Request $request, $id)
 {
     $article = $this->doctrine->getRepository('CoreBundle:Article')->find($id);
     $commentaire = new Commentaire();
     $commentaire->setdateCreation(new \Datetime());
     $commentaire->setArticle($article);
     $user = $this->user->getToken()->getUser();
     $commentaire->setAuteur($user);
     $form = $this->formbuilder->create(CommentaireType::class, $commentaire);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->doctrine->persist($commentaire);
         $this->doctrine->flush();
         $this->session->getFlashBag()->add('success_article', 'Le message a bien été ajouté');
     }
     return $form;
 }
Ejemplo n.º 2
0
 /**
  * Add commentaire.
  *
  * @param \CoreBundle\Entity\Commentaire $commentaire
  *
  * @return Article
  */
 public function addCommentaire(\CoreBundle\Entity\Commentaire $commentaire)
 {
     $this->commentaires[] = $commentaire;
     $commentaire->setArticle($this);
     return $this;
 }