Symfony Doctrine can't find fixtures to load

前端 未结 2 1251
感动是毒
感动是毒 2021-01-25 12:10

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 Load         


        
相关标签:
2条回答
  • 2021-01-25 12:30

    Depending on what version of fixtures you use you should extend/implement different classes. If the version is >= 3.0 then

    extend Fixture (use Doctrine\Bundle\FixturesBundle\Fixture;)
    

    If < 3.0

    implements FixtureInterface, ContainerAwareInterface
    
    0 讨论(0)
  • 2021-01-25 12:55

    In LoadDataFixturesDoctrineCommand.php line 95:

    Could not find any fixture services to load.

    A Resolution: for symfony 3.4.* and doctrine-fixtures-bundle 3.0 ~/src/YC/PlatformBundle/DataFixtures/LoadCategory.php

    namespace YC\PlatformBundle\DataFixtures;
    
    use Doctrine\Bundle\FixturesBundle\Fixture;
    
    use Doctrine\Common\Persistence\ObjectManager;
    
    use YC\PlatformBundle\Entity\Categorie;
    
    
    class LoadCategory extends Fixture
    {
    
      public function load(ObjectManager $manager)
      {
        $names = array(
            'Développement web',
            'Développement mobile',
            'Graphisme',
            'Integration',
            'Reseau'
        );
    
        foreach ($names as $name) {
            $category = new Categorie();
            $category->setName($name);
            $manager->persist($category);
        }
    
        $manager->flush();
      }
    

    }

    ~/src/YC/PlatformBundle/DataFixtures/LoadCategory.php

    YC\PlatformBundle\DataFixtures:

        resource: '%kernel.project_dir%/src/YC/PlatformBundle/DataFixtures'
        tags: ['doctrine.fixture.orm']
    
    0 讨论(0)
提交回复
热议问题