【发布时间】:2019-08-24 19:03:09
【问题描述】:
我有一个实体(大约 20/25 个字段),我想用表单对其进行编辑。
我只想编辑(和显示)几个表单域。
问题是,所有显示的字段都正确更新,但未渲染的字段默认更新为“null”值。
我的控制器:
$em = $this->getDoctrine()->getManager();
$LaboRequest= $em->getRepository('MyBundle:LaboRequest')->find($id);
$form = $this->createForm('MyBundle\Form\LaboRequestType', $LaboRequest);
if ($request->isMethod('POST') && $form->handleRequest($request)->isSubmitted() && $form->isValid()) {
$em->persist($LaboRequest);
$em->flush();
return $this->redirectToRoute(...);
}
return $this->render('...', array(
'LaboRequest' => $LaboRequest,
'form' => $form->createView(),
));
我只在我的视图中渲染几个字段,所以我可以理解,默认情况下,symfony 对不渲染的字段使用“null”。
但是有没有办法编辑实体的一部分而不影响具有“null”值的实体的数据?
【问题讨论】:
-
您是否有包含所有字段的表单,但您只呈现其中的一部分?如果是这种情况,请尝试使用不同的表格或validation groups