Created
July 25, 2015 19:28
-
-
Save ahonymous/17bdb65e723b3a580803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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