2016-05-11 7 views
2

1-オブジェクトを渡すためにredirectToRoute()を使用できますか?関数にパラメータを渡して経路を変更する方法

$ccp = new Ccp(); 
return ($this->redirectToRoute("_indexAccountCcpClient",array('ccp'=>$ccp))); 

これは私のYMLルーティングです:

_indexCcpClient: 
    path:  /index 
    defaults: { _controller: EgovPosteBundle:Ccp:indexCcp } 

_indexAccountCcpClient: 
    path:  /account/index 
    defaults: { _controller: EgovPosteBundle:Ccp:indexAccountCcp } 

私のコントローラ

public function indexCcpAction() 
    { 
     $demanceCCP = new DemandeCCP(); 
     $ccp = new Ccp(); 
     $formDemanceCCP = $this->createForm(new DemandeCcpType(), $demanceCCP); 
     $formCcp = $this->createForm(new LoginCcpType(), $ccp); 
     $formCcp->handleRequest($this->get('request')); 
     $formDemanceCCP->handleRequest($this->get('request')); 
     $em = $this->getDoctrine()->getManager(); 
     if ($this->get("request")->getMethod() == "POST") { 
      if ($this->get("request")->request->has("DemandeCcpType")) { 
       $demanceCCP = $formDemanceCCP->getData(); 
       $em->persist($demanceCCP); 
       $em->flush(); 
      } 
      if ($this->get("request")->request->has("LoginCcpType")) { 
       $ccp = $formCcp->getData(); 
       $dbCcp = $this->getDoctrine()->getRepository('EgovCoreBundle:Ccp') 
        ->findOneBy(array('numCompte' => $ccp->getNumCompte(), 'mdp' => $ccp->getMdp())); 
       if (!$dbCcp) { 
        throw $this->createNotFoundException('No Data found for id '); 
       } else { 
        self::indexAccountCcpAction($ccp); 
        //return ($this->redirectToRoute("_indexAccountCcpClient",array('ccp'=>$ccp))); 
       } 
      } 
     } 
     return $this->render('@EgovPoste/Ccp/indexCcp.html.twig', 
      array('formDemandeCcp' => $formDemanceCCP->createView(), 
        'formLogin' => $formCcp->createView()) 
     ); 
    } 
public function indexAccountCcpAction(Ccp $ccp) 
    { 
     //echo ($ccp->getNumCompte()); 

     return $this->render('EgovPosteBundle:Ccp:indexAccountCcp.html.twig', array('ccp' => $ccp)); 
    } 

だから私のprobleme iがindexAccountCcpAction(CCP $ CCP)関数を呼び出すとへのルートパスを変更する方法です/ account/index

私のコードでは正常に動作しますが、同じパスを使用します。/ index

答えて

1

オブジェクトをコントローラに渡すことはできません。リダイレクト時には、任意のURLのように文字列値を渡すことしかできません。

リダイレクト時にidを$ dpCcpからコントローラに渡し、indexAccountCcpActionでリポジトリメソッドを使用してデータベースからオブジェクトをロードします。

関連する問題