dourunlao1642 2014-02-19 10:28
浏览 57
已采纳

Symfony2:如何返回发送表单请求的页面

I have a link: mysite/productnumber_2.html. On this Site I have a formular in a twig template, the action of this form leads to .../createAssessment.

In my controller I do things like save in a DB.

My question is, how can I go back to the url mysite/productnumber_2.html?

My function in teh controller looks like this:

/**
 *
 * @Route(path = "/createassessment", name="create_assessment", methods = "POST")
 * @param Request $request The Request object
 * @return RedirectResponse
 */
public function createAssessmentAction(Request $request) {
$form = $this->createForm(new AssessmentType());
$form->handleRequest($request);

if ($form->isValid()) {

    $assessment = $form->getData();

    $em = $this->getDoctrine()->getManager();

    $em->persist($assessment);
    $em->flush();

    return $this->redirect( ## WHAT DO I HAVE TO PUT HERE?? ## );
}
}
  • 写回答

1条回答 默认 最新

  • dongqishun6409 2014-02-19 10:31
    关注

    You could redirect for request referer:

    return $this->redirect($request->headers->get('referer'));
    

    Or even better for defined route:

    return $this->redirect($this->generateUrl('your_route'));
    

    where your_route is path to you mysite/productnumber_2.html page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)