dev-master
9999999-devZend Framework 2 integration with the Doctrine Fixtures library
The Requires
zf2 doctrine fixtures
Zend Framework 2 integration with the Doctrine Fixtures library
The EwgoDoctrineFixtures module provides ZF2 integration with the Doctrine Fixtures library., (*1)
``` bash $ php composer.phar require ewgo/doctrine-fixtures-module, (*2)
Add "EwgoDoctrineFixtures" to the list of loaded modules. ## Configuration Add the paths to the fixtures in your modules configuration ``` php array( 'doctrinefixtures' => array( 'paths' => array( 'MyModule' => __DIR__ . '/../src/MyModule/DataFixtures/ORM' ) ) )
Create your fixture classes.
You can implement Zend\ServiceManager\ServiceLocatorAwareInterface in order to use the ServiceManager in your fixture class.
You can also directly extend EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture in order to get the benefits of both ServiceLocatorAwareInterface and AbstractFixture., (*3)
``` php namespace MyModule\DataFixtures\ORM;, (*4)
use EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture; use Doctrine\Common\Persistence\ObjectManager; use MyModule\Entity\User;, (*5)
class LoadUserData extends ServiceLocatorAwareAbstractFixture { public function load(ObjectManager $manager) { // Encode the password any way you want $password = $this->serviceLocator->get('MySuperEncoder')->encode('myAwesomePassword');, (*6)
$user = new User(); $user->setUsername('test'); $user->setPassword($password); $user->setPassword('test@test.com'); $manager->persist($user); $manager->flush(); }
}, (*7)
``` bash $ vendor/bin/doctrine-module fixtures:load
See the help (--help) for options., (*8)
For more information see the Doctrine Fixtures documentation., (*9)
Zend Framework 2 integration with the Doctrine Fixtures library
zf2 doctrine fixtures