Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function executePostComment(sfWebRequest $request)
- {
- // var_dump($this->article);
- // $request->getParameter('slug');
- // Checks CommentForm
- $this->forwardUnless($request->isMethod('post'), 'article', 'show');
- // Checks Article
- $this->article = $this->getRoute()->getObject();
- $this->forwardUnless($this->article, 'article', 'show');
- // Initialize CommentForm
- $this->commentForm = new CommentForm();
- // Checks CommentForm
- $this->commentForm->bind($request->getParameter('comment'));
- if($this->commentForm->isValid())
- {
- // Add Comment to Article
- $comment = new Comment();
- $comment->setArticleId($this->article->getId());
- $comment->setAuthorName($this->getRequestParameter('comment[name]'));
- $comment->setAuthorEmail($this->getRequestParameter('comment[email]'));
- $comment->setAuthorUrl($this->getRequestParameter('comment[url]'));
- $comment->setAuthorIp($request->getHttpHeader('addr','remote'));
- $comment->setContent($this->getRequestParameter('comment[message]'));
- $comment->save();
- // Set Notice
- $this->getUser()->setFlash('notice',"Votre commentaire a bien été ajouté !");
- $this->commentForm = new CommentForm();
- }
- // Set Show Template
- $this->setTemplate('show');
- }
Add Comment
Please, Sign In to add comment