Skip to content

Instantly share code, notes, and snippets.

@ahonymous
Created July 25, 2015 19:28
Show Gist options
  • Save ahonymous/17bdb65e723b3a580803 to your computer and use it in GitHub Desktop.
Save ahonymous/17bdb65e723b3a580803 to your computer and use it in GitHub Desktop.
public function addCommentAction(Request $request)
{
$comment = new Comment();
$form = $this->createForm(new CommentFormType(),$comment);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$project_id = $request->request->get('project_id');
$project = $this->getDoctrine()
->getRepository('RedmineBundle:Project')
->find($project_id);
if (!$project) {
throw $this->createNotFoundException('Project not found for id '.$project_id);
}
$data = $form->getData();
$data->setUser($this->getUser());
$data->setProject($project);
$em = $this->getDoctrine()->getManager();
$em->persist($data);
$em->flush();
$html = $this->renderView('RedmineBundle:Comment:comment.html.twig',array('comment'=>$comment));
$response = new Response(json_encode(array('html' => $html)));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment