【发布时间】:2016-08-01 14:28:27
【问题描述】:
我希望在提交表单后不要刷新我的页面。
我使用重定向并再次询问实体列表但没有没有变化,我仍然需要刷新。 我对其他表单也有同样的问题,但重定向解决了它。
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重新加载。有没有办法调用控制器来渲染新资源?
【问题讨论】:
-
我还是有这个问题。我试过 $this->redirectToRoute('accueil', array(), 302/301);没有变化。
标签: forms redirect submit symfony page-refresh