In Symfony 2 you could do something like this to get nested query string data:
// mixed getInt(string lookup, mixed default, bool deep)
$request->query->getInt('page[number]', 1, true);
In Symfony 3 it looks like the ability to retrieve deeply nested data has been removed in favour of retrieving the top level array and getting the data directly.
// mixed get(string key, mixed default)
(int) $request->query->get('page', ['number' => 1])['number']
Can anyone confirm that I'm not missing something here and this is now the preferred method to retrieve nested data in parameter bags?
I did look over the 3.1 docs and all examples reference retrieval of the array with no options to query for deeply nested data.
You could use the PropertyAccess component:
$query = $request->query->all();
$accessor = PropertyAccess::createPropertyAccessor();
$page = (int) $accessor->getValue($query, '[page][number]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With