Symfony表单-数据时间增加+30分钟

时间:2018-11-22 20:46:02

标签: forms symfony

当我在Forms中设置beginAt(DateTime)时,我想在“ endAt”中设置相同的日期,但要+30分钟。我不知道如何做到这一点:(

第一个代码是我项目中的Form部分,第二个代码是添加约会的函数“ new Appointment”。

$builder
                ->add('title', TextType::class, ['label'=>'Tytuł'])
                ->add('description', TextType::class, ['label'=>'Treść'])
                ->add('beginAt')
                ->add('endAt')


            ;



public function new(Request $request, $id, TokenStorageInterface $tokenStorage): Response
    {
        $currentUser = $tokenStorage->getToken()
                ->getUser();

        $username = $currentUser->getUsername();

        $appointment = new Appointments();
        $appointment->setDoctor($id);
        $appointment->setUsername($username);
        $form = $this->createForm(AppointmentsType::class, $appointment);

        $form->handleRequest($request);


        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($appointment);
            $em->flush();

            return $this->redirectToRoute('przychodnia_index');
        }


        return $this->render('appointments/new.html.twig', [
            'appointment' => $appointment,
            'form' => $form->createView(),
        ]);
    }

1 个答案:

答案 0 :(得分:0)

例如,尝试使用Symfony Form Events更新Submit的endAt字段,并使用一些Ajax动态提交表单。这里有一个很棒的教程(以法语对不起)https://www.grafikart.fr/tutoriels/champs-imbriques-888