所以我在页面上,看起来像:
project2/web/calculator
当我点击表单中的提交时,我想重定向到这样的地址:
project2/web/result?weight=80&height=190
我该怎么做?我只知道如何显示这些参数:
if ($form->isValid())
{
$weight = $form->get('weight')->getData();
$height = $form->get('height')->getData();
return new Response('Test: ' . $weight . ' ' . $height);
}
假设您定义了一个名为result
的路由,该路由与URL project2/web/result
匹配,并且假设您在Controller
中,那么您可以使用所需的查询参数重定向到该路由,例如:
return $this->redirect($this->generateUrl('result', array(
'height' => $height,
'weight' => $weight
));
也就是说,在我看来,你似乎在试图做一些奇怪的事情——为什么你需要重定向到另一条路线?我需要更多的细节,但在一个正常的Symfony2场景中,你可能想要呈现一个传递这些值的Twig模板:
return $this->render('result_view', array(
'height' => $height,
'weight' => $weight
));