I'm in the need of using fixtures for putting an initial user into my database.
I had a look at this module which is said to be pretty good: https://github.com/doctrine/data-fixtures
Unfortunately I don't understand how to use it. Alright, I build a class with my fixtures. And then? I'm used to fixtures in the way that when I create my database (schema-tool:create
) that the data is automatically written into it.
But where is this connection? It seems that you have to call the Loader at some point in the code?
Would be great if someone could give me a short tutorial how to utilize these (or any other working) fixture module!
Thanks!
The fixtures are not available yet in the DoctrineModule
. There is a distinct module for specifically fixture loading with Doctrine and it's called the DoctrineDataFixtureModule
and can be found on GitHub.
Install it via composer: hounddog/doctrine-data-fixture-module
and enable DoctrineDataFixtureModule
in your application.config.php. If you configured doctrine already, just add this to your FooModule
's module.config.php:
'data-fixture' => array(
'location' => __DIR__ . '/../fixtures',
)
And in that module's directory create a subdirectory called "fixtures". Put your classes there and run vendor/bin/doctrine-module data-fixture:import
to import the fixtures. An example of a fixture class could look like this
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