Symfony2 Doctrine iterate over with while next()

Viewed 10601

I'm looking for a working solution, to iterate over a PersistentCollection in . Unfortunately this seems not to work? Symfony ignores the next() function!

while (($animal = $zooAnimals->next()) !== false) {

    $color = $animal->getColor();

    print_r($color); die; // Test and die
}

print_r('Where are the animals?'); die; // << Current result

Reference: Doctrine\ODM\MongoDB\PersistentCollection

4 Answers

This is my solution,

$zooAnimals->getIterator();

while ($animal = $zooAnimals->current()) {

    echo $animal->getColor();

    $zooAnimals->next();
}
Related