Php Symfony-同时发送带URL和不带URL的参数
我想同时发送URL中的一些参数(使用redirectToRoute)和URL中的一些参数(使用render)。我该怎么办 举个例子:我有两个变量:A和B A需要在URL中: 需要发送B来完成细枝(但不是通过URL) 你能给我举个代码的例子吗Php Symfony-同时发送带URL和不带URL的参数,php,symfony,get,Php,Symfony,Get,我想同时发送URL中的一些参数(使用redirectToRoute)和URL中的一些参数(使用render)。我该怎么办 举个例子:我有两个变量:A和B A需要在URL中: 需要发送B来完成细枝(但不是通过URL) 你能给我举个代码的例子吗 非常感谢非常简单,只需将一组键/值传递到render()方法: $template = $twig->load('index.html'); echo $template->render(array('the' => 'variables'
非常感谢非常简单,只需将一组键/值传递到
render()
方法:
$template = $twig->load('index.html');
echo $template->render(array('the' => 'variables', 'go' => 'here'));
HTTP 3xx重定向没有正文,因此您不能通过
渲染包含数据,同时使用重定向路由(“重定向目标路由”,数组('A'=>'smth')
)
您需要将数据保存在一个会话flashbag中,并从那里获取重定向\目标\路由的控制器操作中的数据
public function redirectingAction(Request $request)
{
// ...
// store the variable in the flashbag named 'parameters' with key 'B'
$request->getSession()->getFlashBag('parameters')->add('B', 'smth_else');
// redirect to uri?A=smth
return $this->redirectToRoute('redirect_target_route', array('A' => 'smth'});
}
public function redirectTargetAction(Request $request)
{
$parameterB = $request->getSession()->getFlashBag('parameters')->get('B');
// ...
}
或者使用这种方法,我不认为@Destunk想要传递变量来渲染,而是通过重定向存储/检索它们,因为问题中提到了redirectToRoute
。