drakulitka / doctrine-data-fixture-module
提供 Doctrine Data-Fixture 功能的 Zend Framework 3 模块
1.0.2
2018-06-27 23:21 UTC
Requires
- php: ^7.0 || ^7.2
- doctrine/data-fixtures: v1.3.1
- doctrine/doctrine-orm-module: ^2.1
- zendframework/zend-eventmanager: ^3.2
- zendframework/zend-modulemanager: ^2.8
- zendframework/zend-servicemanager: ^3.3
This package is not auto-updated.
Last update: 2024-09-21 02:55:14 UTC
README
简介
这是从 dkorsak/doctrine-data-fixture-module 分支出来的。
DoctrineDataFixtureModule 模块旨在将 Doctrine2 ORM Data Fixtures 集成到 Zend Framework 3。
安装
此模块使用 composer 进行安装。有关 composer 文档,请参阅 getcomposer.org。
$ php composer.phar require drakulitka/doctrine-data-fixture-module
然后打开 config/application.config.php
并将 DoctrineModule
、DoctrineORMModule
和 DoctrineDataFixtureModule
添加到您的 modules
。
注册固定值
要使用 Doctrine 模块注册固定值,请在您的配置中添加固定值。
<?php return [ 'doctrine' => [ 'fixture' => [ 'YourModuleName' => __DIR__ . '/../src/Fixture', ], ], ];
用法
默认
./vendor/bin/doctrine-module orm:fixtures:load
清除并截断,不进行确认
./vendor/bin/doctrine-module orm:fixtures:load -n --purge-with-truncate
追加数据而不是删除
./vendor/bin/doctrine-module orm:fixtures:load -n --append
如何将容器注入固定值文件
<?php namespace YourModuleName\Fixture; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use DoctrineDataFixtureModule\ContainerAwareInterface; use DoctrineDataFixtureModule\ContainerAwareTrait; class LoadUser implements FixtureInterface, ContainerAwareInterface { use ContainerAwareTrait; /** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $myService = $this->container->get('my_service'); } }