修改请求参数的值

时间:2012-05-22 18:59:58

标签: symfony

我想知道是否可以修改请求参数的值。

但我不知道该怎么做。

我尝试

$requestContent = $this->getRequest()->request->get('tactill_customerbundle_customertype');

接下来我使用

$request->request->replace()

但我不知道如何在我的情况下使用这种方法。

由于

1 个答案:

答案 0 :(得分:30)

replace方法取代了请求中所有的参数,因此您可能不希望这样做。

我会使用set方法 - 所以你可以这样做:

$request->request->set('tactill_customerbundle_customertype', $newValue)

您可以在Symfony2文档(http://api.symfony.com/2.0/)中阅读更多内容 - 您正在寻找Symfony\Component\HttpFoundation\Request$request变量),然后在Symfony\Component\HttpFoundation\ParameterBag变量时返回request()你调用{{1}}方法。