コード例 #1
0
 /**
  * @Route("/notebook/project/create/", name="projectCreate")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $dateTimeFormat = $this->container->getParameter('AppBundle.dateTimeFormat');
     $name = $request->request->get('name');
     $date = new \DateTime("now");
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $userId = $user->getId();
     $project = new Project();
     $project->setUserId($userId);
     $project->setName($name);
     $project->setDateCreated($date);
     $project->setDateModified($date);
     $project->setIsCompleted(false);
     $em = $this->getDoctrine()->getManager();
     $em->persist($project);
     $em->flush();
     $url = $this->generateUrl('singleProject', array('id' => $project->getId()));
     $response = new JsonResponse(array('id' => $project->getId(), 'name' => $project->getName(), 'date' => $project->getDateModified()->format($dateTimeFormat), 'url' => $url));
     return $response;
 }