コード例 #1
0
ファイル: DefaultController.php プロジェクト: thomasage/asso
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  *
  * @Route("/accounting/add",
  *        name="app_accounting_add",
  *        methods={"GET","POST"})
  */
 public function addAction(Request $request)
 {
     // Transaction
     $transaction = new Transaction();
     $transaction->addDetail(new TransactionDetail());
     // Edit form
     $formEdit = $this->createForm(TransactionType::class, $transaction);
     $formEdit->handleRequest($request);
     if ($formEdit->isSubmitted() && $formEdit->isValid()) {
         // Save data
         $tm = $this->get('app.transaction_manager');
         $tm->update($transaction, $formEdit);
         // Flash message
         $this->addFlash('success', $this->get('translator')->trans('add.success.added', [], 'accounting'));
         // Redirect
         if (!is_null($request->request->get('add_and_close'))) {
             return $this->redirectToRoute('app_accounting_homepage');
         } elseif (!is_null($request->request->get('add_and_new'))) {
             return $this->redirectToRoute('app_accounting_add');
         } else {
             return $this->redirectToRoute('app_accounting_edit', ['transaction' => $transaction->getId()]);
         }
     }
     // Render
     return $this->render('accounting/add.html.twig', ['formEdit' => $formEdit->createView()]);
 }