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));
}
所以我的问题是如何调用indexAccountCcpAction(Ccp $ ccp)函数并将路径路径更改为/ account / index
在我的代码中它运行正常,但路径相同:/ index
答案 0 :(得分:1)
您无法将对象传递给控制器,只能在重定向时传递字符串值,就像在任何URL中一样。
因此,在重定向时将id从$ dpCcp传递给控制器,然后在indexAccountCcpAction中使用存储库方法从数据库加载对象。