2

I want to add a parameter to the ParameterBag in a symfony2 Request.

So the array looks like this:

array (size=2)
  'editor' => 
    array (size=6)
      '_token' => string '5797a4faf1fced89404b80fb04b3cadffc99695e' (length=40)
      'login' => string 'editor' (length=6)
      'firstName' => string 'Joh' (length=3)
      'lastName' => string 'Ha' (length=2)
      'address' => 
        array (size=6)
          'time_zone_code' => string 'Africa/Abidjan' (length=14)

And I want to add a field to the editor array. I tried this

$request->request->add(array('editor[password]' => $password));

But of course this just adds a field named editor[password] after the editor array.

Do I have to replace the whole ParameterBag or is there a method to add the value?

1 Answer 1

8

You can get the editor array and then add a value to it and set it again if editor is not the only array in the ParameterBag:

$data = $this->getRequest()->request->get('editor');
$data['password'] = 'string';
$this->getRequest()->request->set('editor', $data);

Edit

Looks like there is a question in a google group that is similar with a similar answer: https://groups.google.com/forum/?fromgroups=#!topic/symfony-devs/2-SWFtFKwxQ

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.