Skip to content

Instantly share code, notes, and snippets.

@merk
Created April 30, 2011 05:30
Show Gist options
  • Save merk/949452 to your computer and use it in GitHub Desktop.
Save merk/949452 to your computer and use it in GitHub Desktop.
<?php
public function createAction($threadIdentifier)
{
$thread = $this->container->get('fos_comment.manager.thread')->findThreadByIdentifier($threadIdentifier);
if (!$thread) {
throw new NotFoundHttpException(sprintf('Thread with identifier of "%s" does not exist', $threadIdentifier));
}
if ($replyToId = $this->container->get('request')->request->get('reply_to')) {
$parent = $this->container->get('fos_comment.manager.comment')->findCommentById($replyToId);
if (!$parent) {
throw new NotFoundHttpException(sprintf('Parent comment with identifier "%s" does not exist', $replyToId));
}
} else {
$parent = null;
}
$comment = $this->container->get('fos_comment.manager.comment')->createComment($thread, $replyTo);
$form = $this->container->get('fos_comment.form_factory.comment')->createForm();
$form->setData($comment);
$request = $this->container->get('request');
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid() && $this->container->get('fos_comment.creator.comment')->create($comment, $parent)) {
return $this->onCreateSuccess($form);
}
}
return $this->onCreateError($form);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment