I have a form to upload documents and each document can be assigned to one or several agencies. every Agency belongs to one specific market and one market can have several agencies. In my form, only the agencies can be selected but when listing my created document, I want the markets of the agencies to be listed, as well. So now to my question: I'm looking for a way to access every single object of the arraycollection "agency" and then use my getter for the markets on each of these objectc to get and then set the markets for the document that has been created. It's hard to describe it all properly, so feel free to ask whatever is unclear! I'd be happy about any help!
1 Answer
ArrayCollection is iterable. So you can simply do something like:
foreach($document->getAgencies() as $agency) {
$agency->getMarket();
}
4 Comments
sonja
thanks! that's exactly what I've been looking for! Only now, I don't get any values back. so it seems as if it's null, even though something has been selected..
Ramy Nasr
You must do this after the form has been submitted and processed and the form you are using must know how to update your entities. This would be beyond the scope of this question, but you will need to do some debugging. I can't help much without looking at the code.
sonja
I asked a new question to that topic with code right there: stackoverflow.com/questions/45983542/… :))
Alvin Bunk
This should be marked as the correct answer sonja. This is exactly what would be done.