ewgo / doctrine-fixtures-module
此包的最新版本(dev-master)没有提供许可证信息。
Zend Framework 2 与 Doctrine Fixtures 库的集成
dev-master
2013-07-26 16:48 UTC
Requires
- doctrine/data-fixtures: dev-master
- doctrine/doctrine-module: ~0.7
- zendframework/zendframework: 2.*
This package is not auto-updated.
Last update: 2024-09-24 03:49:11 UTC
README
关于
EwgoDoctrineFixtures 模块提供 ZF2 与 Doctrine Fixtures 库的集成。
安装
$ php composer.phar require ewgo/doctrine-fixtures-module
将 "EwgoDoctrineFixtures" 添加到已加载模块列表中。
配置
在模块配置中添加 fixtures 的路径
array( 'doctrinefixtures' => array( 'paths' => array( 'MyModule' => __DIR__ . '/../src/MyModule/DataFixtures/ORM' ) ) )
使用方法
创建您的 fixture 类。
您可以在 fixture 类中实现 Zend\ServiceManager\ServiceLocatorAwareInterface 以使用 ServiceManager。
您还可以直接扩展 EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture 以获得 ServiceLocatorAwareInterface 和 AbstractFixture 的好处。
namespace MyModule\DataFixtures\ORM; use EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture; use Doctrine\Common\Persistence\ObjectManager; use MyModule\Entity\User; class LoadUserData extends ServiceLocatorAwareAbstractFixture { public function load(ObjectManager $manager) { // Encode the password any way you want $password = $this->serviceLocator->get('MySuperEncoder')->encode('myAwesomePassword'); $user = new User(); $user->setUsername('test'); $user->setPassword($password); $user->setPassword('test@test.com'); $manager->persist($user); $manager->flush(); } }
$ vendor/bin/doctrine-module fixtures:load
查看帮助 (--help) 了解选项。
更多详细信息请参阅 Doctrine Fixtures 文档。