Guest User

Untitled

a guest
Jun 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public function executePostComment(sfWebRequest $request)
  2. {
  3.  
  4. // var_dump($this->article);
  5.  
  6. // $request->getParameter('slug');
  7.  
  8. // Checks CommentForm
  9. $this->forwardUnless($request->isMethod('post'), 'article', 'show');
  10.  
  11. // Checks Article
  12. $this->article = $this->getRoute()->getObject();
  13. $this->forwardUnless($this->article, 'article', 'show');
  14.  
  15. // Initialize CommentForm
  16. $this->commentForm = new CommentForm();
  17.  
  18. // Checks CommentForm
  19. $this->commentForm->bind($request->getParameter('comment'));
  20.  
  21. if($this->commentForm->isValid())
  22. {
  23. // Add Comment to Article
  24. $comment = new Comment();
  25. $comment->setArticleId($this->article->getId());
  26. $comment->setAuthorName($this->getRequestParameter('comment[name]'));
  27. $comment->setAuthorEmail($this->getRequestParameter('comment[email]'));
  28. $comment->setAuthorUrl($this->getRequestParameter('comment[url]'));
  29. $comment->setAuthorIp($request->getHttpHeader('addr','remote'));
  30. $comment->setContent($this->getRequestParameter('comment[message]'));
  31. $comment->save();
  32.  
  33. // Set Notice
  34. $this->getUser()->setFlash('notice',"Votre commentaire a bien été ajouté !");
  35.  
  36. $this->commentForm = new CommentForm();
  37. }
  38.  
  39. // Set Show Template
  40. $this->setTemplate('show');
  41. }
Add Comment
Please, Sign In to add comment