在Symfony 2.7中,我在索引页面上使用锚。该页面还包含一个表单,允许我过滤显示的元素。如果我使用锚点在页面内导航,则URL中会出现锚点。然后,如果我点击表单的提交按钮,过滤器就会被应用,页面就会被新内容刷新。问题是URL中的锚在这个过程中没有消失,刷新后,页面向下滚动到我访问的最后一个锚点。提交表格后,我如何重置URL?
以下是我的行动代码:
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$dailyPlanning = $em
->getRepository('AppBundle:Planning')
->findOneBy(array('day' => (new \DateTime)));
//....//
$filter = new Filter($param, $param2);
$form = $this->createForm(new FilterType(), $filter);
$form->handleRequest($request);
if ($form->isValid()) {
$dailyPlanning->applyFilter($filter);
}
return $this->render('AppBundle:Workflow:index.html.twig', array(
'planning' => $dailyPlanning,
'form' => $form->createView(),
'filterHidden' => $filter->allChecked(),
));
}
1条答案
按热度按时间11dmarpk1#
有点老问题了...但迟到总比没有好:)在Symfony 5.4上测试
这将强制URL在提交后重新创建,原始URL将不会被使用。