当用户在edit_form上编辑数据(例如)然后单击提交按钮时,他会被重定向到页面,其中的更改应该是可见的。
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ClientBundle:Client')->find($id);
$kdnr = $entity->getKdnr();
if (!$entity) {
throw $this->createNotFoundException($this->get('translator')->trans('client.messages.notfound'));
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
$entity->setKdnr($kdnr);
if ($editForm->isValid()) {
$em->flush();
$this->getRequest()->getSession()->getFlashBag()->add('notice', $this->get('translator')->trans('messages.savenotice'));
return $this->redirect($this->generateUrl('client_show', array('id' => $id)));
}
return $this->render('ClientBundle:Client:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
之后,该消息可见,但更改仅在刷新页面后可见。并且页面刷新后消息才会消失。当我离开视图并再次访问时,消息仍然存在。
是否可能在表单提交后直接显示更改并且消息仅显示一次?这是会话问题吗?