dkorsak / doctrine-data-fixture-module
提供 Doctrine Data-Fixture 功能的 Zend Framework 3 模块
1.0.0
2016-11-14 13:43 UTC
Requires
- php: >=5.5.9
- doctrine/data-fixtures: ^1.1
- doctrine/doctrine-orm-module: ^1.1
- zendframework/zend-eventmanager: ~3.0
- zendframework/zend-modulemanager: ~2.0
- zendframework/zend-servicemanager: ~3.0
This package is not auto-updated.
Last update: 2024-09-15 00:45:16 UTC
README
介绍
这是从 Houndog/DoctrineDataFixtureModule 分支出来的。
DoctrineDataFixtureModule 模块旨在将 Doctrine2 ORM Data Fixtures 与 Zend Framework 3 集成。
安装
此模块的安装使用 composer。有关 composer 的文档,请参阅 getcomposer.org。
$ php composer.phar require dkorsak/doctrine-data-fixture-module
然后打开 config/application.config.php
并将 DoctrineModule
、DoctrineORMModule
和 DoctrineDataFixtureModule
添加到您的 modules
中
注册 fixture
要使用 Doctrine 模块注册 fixture,请将 fixture 添加到您的配置中。
<?php return array( 'doctrine' => array( 'fixture' => array( 'ModuleName' => __DIR__ . '/../src/ModuleName/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
如何将容器注入到 fixture 文件中
<?php namespace Application\DataFixtures; 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'); } }