2017-06-17 83 views
-1

我有一個問題,這裏是項目:問題與重定向的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

看看路由名稱它是awnser,它應該是答案(不知道這是否會解決問題) –

+0

@RumenPanchev這只是一個打字錯誤,因爲我改名爲一切。 – Cesar

回答

1

您可以將用戶重定向到您想要的位置。使用以下方法:

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

我已經設法得到Quizz ID並將其添加到您的功能,它工作得很好! – Cesar