Skip to content

Instantly share code, notes, and snippets.

@aurimasniekis
Created April 28, 2015 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aurimasniekis/75b443a2c73a1a6572a1 to your computer and use it in GitHub Desktop.
Save aurimasniekis/75b443a2c73a1a6572a1 to your computer and use it in GitHub Desktop.
<?php
public function commentNewAction(Request $request, Post $post)
{
$form = $this->createCommentForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var Comment $comment */
$comment = $form->getData();
$comment->setAuthorEmail($this->getUser()->getEmail());
$comment->setPost($post);
$comment->setPublishedAt(new \DateTime());
BackgroundTask::runTask(function($resolve, $reject) use($comment) {
try {
$em = $this->getDoctrine()->getManager();
$em->persist($comment);
$em->flush();
} catch (\Exception $e) {
$reject($e->getMessage());
}
$resolve();
});
return $this->redirectToRoute('blog_post', array('slug' => $post->getSlug()));
}
return $this->render('blog/comment_form_error.html.twig', array(
'post' => $post,
'form' => $form->createView(),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment