C.Astraea
C.Astraea

Reputation: 185

Accessing nested parameters in Symfony ParameterBag

Have a request that looks like this

ParameterBag {#362 ▼
  #parameters: array:1 [▼
    "form" => array:5 [▼
      "titre" => "new b"
      "prix" => "4444"
      "slug" => "with-different-slug"
      "publier" => "unpub"
      "Modifier" => ""
    ]
  ]
}

How can I use the $post = Request::createFromGlobals(); $post->request->has() on those nested properties?

Upvotes: 0

Views: 1860

Answers (1)

Fracsi
Fracsi

Reputation: 2314

ParameterBag's has function does not support deep check. It is just an array_key_exists call.

You could use get with $deep parameter set to true.

E.g.:

$post = Request::createFromGlobals();
$post->request->get('form[titre]', null, true);

It will return null (the second parameter), if the value does not exist.

EDIT:

This function however deprecated in 2.8.

Using paths to find deeper items in get is deprecated since version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.

Upvotes: 3

Related Questions