I starting with Symfony (3.4) and I have problem with load fixture.
When I execute php bin/console doctrine:fixtures:load
then I get message:
In LoadDataFixturesDoctrineCommand.php line 95: Could not find any fixture services to load.
There is my code:
~/src/AppBundle/DataFixtures/ORM/LoadUserData.php
namespace AppBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoadUserData implements FixtureInterface, ContainerAwareInterface {
private $container;
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$user = new User();
$user->setLogin('admin');
$user->setEmail('admin@admin.admin');
$encoder = $this->container->get('security.password_encoder');
$password = $encoder->encodePassword($user, '123qwe');
$user->setPassword($password);
$manager->persist();
$manager->flush();
}
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
~/app/config/services.yml
parameters:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
Thanks.
Depending on what version of fixtures you use you should extend/implement different classes. If the version is >= 3.0 then
If < 3.0
In
LoadDataFixturesDoctrineCommand.php
line 95:A Resolution: for symfony 3.4.* and doctrine-fixtures-bundle 3.0 ~/src/YC/PlatformBundle/DataFixtures/LoadCategory.php
}
~/src/YC/PlatformBundle/DataFixtures/LoadCategory.php
YC\PlatformBundle\DataFixtures: