Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony-同时发送带URL和不带URL的参数_Php_Symfony_Get - Fatal编程技术网

Php Symfony-同时发送带URL和不带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'

我想同时发送URL中的一些参数(使用redirectToRoute)和URL中的一些参数(使用render)。我该怎么办

举个例子:我有两个变量:A和B

A需要在URL中: 需要发送B来完成细枝(但不是通过URL)

你能给我举个代码的例子吗


非常感谢非常简单,只需将一组键/值传递到
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