2016-05-11 155 views
2

1-有可能使用redirectToRoute()傳遞對象嗎?如何將參數傳遞給函數並更改路由

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

這是我的陽明路由:

_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是我怎麼能叫indexAccountCcpAction(CCP $ CCP)功能和修改路由路徑/ account/index

在我的代碼中,它工作正常,但具有相同的路徑:/ index

回答

1

您無法將對象傳遞給控制器​​,您只能在重定向時傳遞字符串值,就像在任何URL中一樣。

因此,當您重定向時將id從$ dpCcp傳遞給控制器​​,然後在indexAccountCcpAction中使用存儲庫方法從數據庫加載對象。

相關問題