我想不会刷新我的网页后提交的表单。
我使用重定向,然后再次询问实体列表,但没有更改,我仍然需要刷新。对于其他形式,我也有同样的问题,但是重定向解决了它。
public function handleClient($client)
{
if (!$client->getNom() || !$this->clientForm->isSubmitted() || !$this->clientForm->isValid())
return;
$this->getDoctrine()->getManager()->persist($client);
$this->getDoctrine()->getManager()->flush();
// HANDLE REFRESH LIST OF CLIENT EXPECTED
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
$this->redirect($this->generateUrl('accueil'));
}
public function clientAction(Request $request)
{
// ACCUEIL
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
// HANDLE CLIENT CREATION AND REQUEST
$this->clientLogicHandler();
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
return $this->render('CommonBundle:Default:index.html.twig',
array('listClients' => $this->listClients)
);
}
}
编辑:我发现问题是我直接调用视图而没有从Controller重新加载。有没有一种方法可以调用控制器,以便呈现新资源?
实际上,重定向仅从操作起作用,而不从子功能起作用。我只需要对操作进行级联,并在需要时进行重定向,例如:
public function handleClient($client)
{
if (!$client->getNom() || !$this->clientForm->isSubmitted() || !$this->clientForm->isValid())
return false;
$this->getDoctrine()->getManager()->persist($client);
$this->getDoctrine()->getManager()->flush();
// HANDLE REFRESH LIST OF CLIENT EXPECTED
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
$this->redirect($this->generateUrl('accueil'));
return true;
}
public function clientAction(Request $request)
{
// ACCUEIL
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
// HANDLE CLIENT CREATION AND REQUEST
if ($this->handleClient())
$this->redirect($this->generateUrl('accueil'));
$repository = $this->getDoctrine()->getManager()->getRepository('CommonBundle:Client');
$this->listClients = $repository->getAllClientInverse();
return $this->render('CommonBundle:Default:index.html.twig',
array('listClients' => $this->listClients)
);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句