i want to insert multiple rows in a loop using doctrine 2..
i usually insert 1 record using this:
$Entity->setData($posted); $this->_doctrine->persist($Entity); $this->_doctrine->flush();
Simply persist all your objects and then call flush() after the loop.
$entityDataArray = array(); // let's assume this is an array containing data for each entity
foreach ($entityDataArray AS $entityData) {
$entity = new \Entity();
$entity->setData($entityData);
$this->_doctrine->persist($entity);
}
$this->_doctrine->flush();
If you're inserting a large number of objects you will want to batch insert (see http://www.doctrine-project.org/docs/orm/2.0/en/reference/batch-processing.html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With