1
时如何发送数据我从数据库中获取一个对象,然后我想打一个重定向到另一个控制器和发送那里对象:symfony的2重定向
$user = $this->getDoctrine()->getRepository('ShopMyShopBundle:Register')->find($id);
return $this->redirect($this->generateUrl('ShopMyShopBundle_homepage'), array('user' => $user));
我怎样才能得到后一个对象重定向并发送到其他控制器功能中的模板,如下所示:
public function indexAction()
{
return $this->render('ShopMyShopBundle:Main:index.html.twig');
}
如何将$ user变量发送到模板。我有&user = $ this-> getDoctrine() - > getRepository('ShopMyShopBundle:Register') - > find($ id);然后我想这样做:return $ this-> render('ShopMyShopBundle:Main:register.html.twig',array('form'=> $ form-> createView(),'user'=> $用户));但我得到一个错误“注意:未定义的变量:用户在...” – user1052836 2012-01-07 19:34:48
这需要SensioFrameworkExtraBundle,顺便说一句。 – 2012-01-08 04:07:50
我发现了一个错误,也许你错了理解我。我忘了使用EntityManager。现在我有:$ em = $ this-> getDoctrine() - > getEntityManager(); $ user = $ em-> getRepository('ShopMyShopBundle:Register') - > find($ id);返回$ this-> render('ShopMyShopBundle:Main:register.html.twig',array('form'=> $ form-> createView(),'user'=> $ user));并在模板中可以使用{{user.login}}; – user1052836 2012-01-08 15:24:11