I'm in the need of using fixtures for putting an initial user into my database.
我需要使用fixture来将初始用户放入我的数据库。
I had a look at this module which is said to be pretty good: https://github.com/doctrine/data-fixtures
我看了一下这个模块据说相当不错: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.
不幸的是我不明白如何使用它。好吧,我用我的灯具建造了一个班级。接着?我习惯于在创建数据库(schema-tool:create)时自动将数据写入其中的方式。
But where is this connection? It seems that you have to call the Loader at some point in the code?
但这种联系在哪里?您似乎必须在代码中的某个位置调用Loader?
Would be great if someone could give me a short tutorial how to utilize these (or any other working) fixture module!
如果有人能给我一个简短的教程如何利用这些(或任何其他工作)夹具模块,那将是很棒的!
Thanks!
谢谢!
1 个解决方案
#1
11
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.
DoctrineModule中尚未提供固定装置。有一个独特的模块用于Doctrine的特定夹具加载,它被称为DoctrineDataFixtureModule,可以在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:
通过composer:hounddog / doctrine-data-fixture-module安装它,并在application.config.php中启用DoctrineDataFixtureModule。如果你已经配置了doctrine,只需将它添加到你的FooModule的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
在该模块的目录中创建一个名为“fixtures”的子目录。将您的类放在那里并运行vendor / bin / doctrine-module data-fixture:import来导入fixture。夹具类的示例可能如下所示
#1
11
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.
DoctrineModule中尚未提供固定装置。有一个独特的模块用于Doctrine的特定夹具加载,它被称为DoctrineDataFixtureModule,可以在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:
通过composer:hounddog / doctrine-data-fixture-module安装它,并在application.config.php中启用DoctrineDataFixtureModule。如果你已经配置了doctrine,只需将它添加到你的FooModule的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
在该模块的目录中创建一个名为“fixtures”的子目录。将您的类放在那里并运行vendor / bin / doctrine-module data-fixture:import来导入fixture。夹具类的示例可能如下所示