Symfony Doctrine找不到要加载的固定装置



i从symfony(3.4)开始,我对负载固定装置有问题。
当我执行php bin/console doctrine:fixtures:load时,我会收到消息:

在LoadDatafixturesdoctrinecommand.php第95行中:  找不到任何固定服务的加载服务。

有我的代码:

〜/src/appbundle/datafixtures/orm/loaduserdata.php

namespace AppBundleDataFixturesORM;
use DoctrineCommonDataFixturesFixtureInterface;
use DoctrineCommonPersistenceObjectManager;
use SymfonyComponentDependencyInjectionContainerAwareInterface;
use SymfonyComponentDependencyInjectionContainerInterface;
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}'
        AppBundleController:
            resource: '../../src/AppBundle/Controller'
            public: true
            tags: ['controller.service_arguments']

谢谢。

取决于使用哪种版本的固定装置,应扩展/实现不同的类。如果版本为> = 3.0,则

extend Fixture (use DoctrineBundleFixturesBundleFixture;)

if<3.0

implements FixtureInterface, ContainerAwareInterface

LoadDataFixturesDoctrineCommand.php第95行中:

找不到加载的任何固定服务。

一个分辨率:对于Symfony 3.4。*和Doctrine-Fixtures-Bundle 3.0 〜/src/yc/platform -bundle/datafixtures/loadCategory.php

namespace YCPlatformBundleDataFixtures;
use DoctrineBundleFixturesBundleFixture;
use DoctrineCommonPersistenceObjectManager;
use YCPlatformBundleEntityCategorie;

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/platform -bundle/datafixtures/loadcategory.php

yc platform -bundle datafixtures:

    resource: '%kernel.project_dir%/src/YC/PlatformBundle/DataFixtures'
    tags: ['doctrine.fixture.orm']

最新更新