Abha Rana
Abha Rana

Reputation: 215

How to get Doctrine entity persistent collection data values with symfony

What is best way to convert Doctrine entity persistent collection to array with symfony 2 ? I want to get the values and later by using that array value, need to get the second entity values which dependent on first entity using form event listener.

Upvotes: 8

Views: 13350

Answers (3)

hmairi halim
hmairi halim

Reputation: 11

For me, I have a relationship between two entities, so I retrieve the values from the related table like this $menu->getGallery()->toArray()

Upvotes: 0

Evgeny Ruban
Evgeny Ruban

Reputation: 1443

If I understand your question correctly, this helps you:

$arrayValues = $persistentCollection->getValues();

Upvotes: 19

Yoann MIR
Yoann MIR

Reputation: 821

$yourCollection->unwrap()->toArray();

That should give you the content of your collection as an array()

Upvotes: 4

Related Questions