我在 Symfony2 框架中有一个表单。成功提交页面后,它会呈现另一个 twig 模板文件,并通过在数组中传递参数来返回值。但是在提交之后,如果我刷新页面,它将再次提交表单并创建表条目。这是在 Controller 中提交后执行的代码,
$this->get('session')->setFlash('info', $this->get('translator')->trans('flash.marca'));
return $this->render('NewBundle:Backend:marca.html.twig', array(
'active' => 1,
'marca' => $marca,
'data' => $dataCamp,
'dataMarca' => $this->getMarcas($admin->getId()),
'admin' => $admin,
));
我希望使用上面提到的参数和警告消息将表单重定向到那里提到的 twig 文件。但我不希望在页面刷新时提交表单。
谢谢
最佳答案
这对我有用:
return $this->redirectToRoute("route_name");
关于php - Symfony2 表单在页面刷新时提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16230041/