Search code examples
symfonydoctrine-orm

Getting values of a POST multi-dimensional array with doctrine


I have a Symfony3 CRM that implements a form to create an invoice. In this form there is a list of different costs, such as labour, service and materials. I have coded this so it's in a multidimensional array since the user can create any number of fields with whatever they want.

An example of the post array:

[costings] => Array
(
    [labour] => 80.30
    [materials] => 75.00
    [service] => 43.50
    ....
)

I want to use Doctrine to get the data. To retrieve the costings array, I use this:

$request->request->get('costings');

But I do not know how to get the values within that array. I tried:

$costings->get('labour');

But I get a warning saying I'm trying to call get() on an array. Is there a way to do this or do I need to revert back to just using $_POST?


Solution

  • Simply use this, since you POST costings as normal array.

    $costings = $request->request->get('costings');
    $labourCostings = $costings['labour'];