forms - Symfony 表单 - 数据时间添加 +30 分钟
问题描述
当我在表单中设置 beginAt(DateTime) 时,我想在“endAt”中设置相同的日期,但 +30 分钟。我不知道该怎么做:(
第一个代码是我项目中的部分表单,第二个代码是添加约会的功能“新约会”。
$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(),
]);
}
解决方案
例如,尝试使用Symfony 表单事件来更新 endAt 字段,并使用一些 ajax 动态提交表单。这里有一个很棒的教程(法语对不起)https://www.grafikart.fr/tutoriels/champs-imbriques-888
推荐阅读
- javascript - 了解 useState 挂钩行为
- docker - 使用 azure CI-CD 将 docker 部署到本地
- python - 熊猫读取特定数量的列,而与数据文件无关
- python - 在 VS Code 中调试时如何解决“ImportError: cannot import”?
- java - JUnit:无法解析 obj
- javascript - Firebase Client JS SDK - 在哪里保存私钥?
- python - 删除字典中具有特定值的键
- azure - 增加 Azure API 管理中的请求超时
- firebase - 其中10个极限Flutter
- rxjs - 为什么使用 share 会阻止使用 withLatestFrom 的 observable?