Environment specific data fixtures with Symfony+Doctrine

前端 未结 2 859
失恋的感觉
失恋的感觉 2021-01-31 19:07

With Smyfony2 and Doctrin2, data fixtures can be created using the following example: http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html

What I wou

2条回答
  •  广开言路
    2021-01-31 19:54

    The easiest way is to put your fixtures into different folders and then load them with the php app/console doctrine:fixtures:load --fixtures=../src/Acme/TestBundle/DataFixtures/ORM/test command. The fixtures option must point to the relative path from where you app folder!

    You can then split up your data into initial, test and so on or create dev, test, staging, prod fixtures, just as you like.

    If you want to mix them up, I don't know any better solution than what I did: I createt a "templates" folder where all fixtures reside in. In my dev folder, I create one class which extends the proper fixture class from template and adjusts what is needed to adjust (like overriding the getOrder method). It's not perfect and I guess one could think about extending the fixtures:load command to take multiple paths, but it works for me.

提交回复
热议问题