当前位置: 动力学知识库 > 问答 > 编程问答 >

symfony2 - 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?

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: