php - How to manage large initial application data in Symfony 2 -


i working on symfony 2 application requires quite lot of initial data. couple of thousand rows easily. ways of managing dataset?

i have been trying docrine migrations it's bit of pain. data loaded once , can't reload. if there bug in data need migration find , correct it, etcetera.

i have been reading on doctrine fixtures. looks more need, required me write php code creates data entities. several thousand entries, going major pain.

any better options?

if data stored in file, can use doctrine data fixtures import data file.

you write fixture class parse data file, set data on new entity, , persit entity.

for example, if data stored in yaml file, work:

// src/acme/demobundle/datafixtures/orm/loadintialdata.php namespace acme\demobundle\datafixtures\orm;  use doctrine\common\datafixtures\fixtureinterface; use doctrine\common\persistence\objectmanager; use acme\demobundle\entity\myentity; use symfony\component\yaml\yaml;  class loadintialdata implements fixtureinterface {      public function load(objectmanager $manager)     {         $filename =             __dir__ .             directory_separator . '..' .             directory_separator . '..' .             directory_separator . 'resources/data/data.yml';          $yml = yaml::parse(file_get_contents($filename));         foreach ($yml $data) {             $entity = new myentity();              $entity->setfoo($data['foo']);             $entity->setbar($data['bar']);              $manager->persist($entity);         }          $manager->flush();     }  } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -