问题重定向symfony

时间:2017-06-17 11:43:53

标签: symfony

我遇到了问题,这是项目:

-> An user answer to a Quizz in POST
-> It submits his answers
-> Calls a controller to flush the POST results
-> Return the user to the homepage (this is the problem, I would like the user to be redirected to that Quizz to see the results).




/**
* Finds and displays a quizz entity.
*
* @Route("/quizz/{id}", name="quizz_answer")
* @Method({"GET", "POST"})
*/
.....
return $this->render('quizz/repondre.html.twig', array(
                        'quizz' => $quizz,
                        'nbrrep' => $questions,
                        'arrayquest' => $arrayQuestions,
                        'delete_form' => $reponseForm->createView(),
));

当用户提交答案时,它会调用:

     /**
     * Finds and displays a quizz entity.
     *
     * @Route("/awnser/", name="save_awnsers")
     * @Method({"POST"})
     */
    public function enregistrerReponseSequence(Request $request) {
        $em = $this->getDoctrine()->getManager();
        $listereponse = $request->request->all();
        $user = $this->getUser();
        foreach ($listereponse as $lareponse) {
            $reponse = $em->getRepository("AppBundle:Reponse_Sequence")->find($lareponse);
            $user->addReponsesSequence($reponse);
        }
        $em->flush();
        return $this->render('base.html.twig');
    }



<form method="POST" action="{{ path("enregistrerReponseSequence")}}" class='form-horizontal'>

我希望用户返回Quizz查看结果。

我想过只需调用控制器来添加结果并刷新页面,但我真的不知道该怎么做。

1 个答案:

答案 0 :(得分:1)

您可以将用户重定向到所需的位置。使用以下方法:

return $this->redirectToRoute('your route name');