コード例 #1
0
 /**
  * Finds and displays a Refuel entity.
  *
  * @Route("/new", name="refuels_new")
  * @Method({"GET", "POST"})
  */
 public function newAction(Request $request, Vehicle $vehicle)
 {
     $refuel = new Refuel();
     $refuel->setDate(new DateTime());
     $vehicle->addRefuel($refuel);
     $form = $this->createForm(RefuelType::class, $refuel, ['action' => $this->generateUrl('refuels_new', ['vehicle_id' => $vehicle->getId()])]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($refuel);
         $em->flush();
         $this->addFlash('success', $this->get('translator')->trans('refuel.created'));
         return $this->redirectToRoute('vehicles_show', ['id' => $vehicle->getId()]);
     }
     return $this->render('refuel/new.html.twig', ['vehicle' => $vehicle, 'refuel' => $refuel, 'form' => $form->createView()]);
 }
コード例 #2
0
 /**
  * Creates a form to delete a Vehicle entity.
  *
  * @param Vehicle $vehicle The Vehicle entity
  *
  * @return Form The form
  */
 private function createDeleteForm(Vehicle $vehicle)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('vehicles_delete', array('id' => $vehicle->getId())))->setMethod('DELETE')->getForm();
 }