Exemplo n.º 1
0
 /**
  * Creates a new note.
  *
  * @Route("/notes/create", name="note_create")
  * @Method({"GET", "POST"})
  *
  * @param Request $request
  *
  * @return Response
  */
 public function createAction(Request $request)
 {
     $user = $this->getUser();
     $padId = $request->query->get('pad');
     $em = $this->getDoctrine()->getManager();
     $note = new Note();
     if ($padId) {
         $pad = $this->get('app.repository.pad')->find();
         $note->setPad($pad);
     }
     $form = $this->createForm(new NoteType($user), $note);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $note = $form->getData();
         $note->setUser($user);
         $em->persist($note);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'Note is successfully created');
         return $this->redirect($this->generateUrl('homepage'));
     }
     return $this->render('AppBundle:Note:create.html.twig', ['form' => $form->createView()]);
 }