Symfony access single entries of arraycollection

95 views Asked by At

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

There are 1 answers

4
Ramy Nasr On

ArrayCollection is iterable. So you can simply do something like:

foreach($document->getAgencies() as $agency) {
    $agency->getMarket();
}