是否可以检索控制器B 中控制器A 生成的html代码?
/**
*
*
* @Route("/{user_id}/cart", name="user_cart")
* @Template()
*/
public function showCartAction($user_id)
{
$cart = $this->getCartManager()
->getUserCart($user_id);
return array(
'cart'=> cart
);
}
/**
*
*
* @Route("/html", name="htmlGenerated")
* @Template()
*/
public function showHTMLAction()
{
$user_id = 3;
$html = //How to obtain the html generated by Controller A with UserId = 3 ????
//...
}
答案 0 :(得分:2)
你可以forward控制器B中的请求
public function showHTMLAction()
{
$user_id = 3;
$html = $this->forward('AcmeDemoBundle:ControllerB:showCardAction', array(
'user_id' => $user_id,
))->getContent();
}
尽管这应该可以完美地运行,但实际上我会建议您在模板中使用embed the controller。