Symfony学说找不到要加载的装置 [英] Symfony Doctrine can't find fixtures to load

查看:96
本文介绍了Symfony学说找不到要加载的装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Symfony(3.4)开始,但是负载夹具有问题.
当我执行php bin/console doctrine:fixtures:load时,我得到消息:

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.

有我的代码:

〜/src/AppBundle/DataFixtures/ORM/LoadUserData.php

~/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

~/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']

谢谢.

推荐答案

根据您使用的灯具版本,您应该扩展/实现不同的类. 如果版本> = 3.0,则

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;)

如果< 3.0

If < 3.0

implements FixtureInterface, ContainerAwareInterface

这篇关于Symfony学说找不到要加载的装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆