修改请求参数的值

Pin*_*nou 25 symfony

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

但我不知道该怎么做.

我试着用

$requestContent = $this->getRequest()->request->get('tactill_customerbundle_customertype');
Run Code Online (Sandbox Code Playgroud)

接下来我用

$request->request->replace()
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Jep*_*Lam 33

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

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

$request->request->set('tactill_customerbundle_customertype', $newValue)
Run Code Online (Sandbox Code Playgroud)

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

  • 使用````replace()````````$ all = $ request-> request-> all(); $ all ['tactill_customerbundle_customertype'] = $ newValue; $ request-> request-> replace($ all);````这允许修改数组参数. (17认同)