我尝试加载夹具时出错

时间:2017-12-01 18:23:34

标签: symfony

当我尝试在控制台中运行load方法时,我收到此错误:

  

[InvalidArgumentException]

     

无法找到要加载的任何灯具服务。

我在AppBundle文件夹下创建了DataFixtures \ ORM,为什么我会收到此错误?

当我有多个捆绑包时,我怎么能告诉Symfony要加载哪个夹具?

namespace AppBundle\DataFixtures\ORM;


use AppBundle\Entity\Movie;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadMovieData implements FixtureInterface
{

    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $movie = new Movie();
        $movie->setTitle('Green Mile');
        $movie->setDescription('fdgs sdfg sdg');
        $movie->setTime(23);
        $movie->setYear(2341);

        $manager->persist($movie);
        $manager->flush();
    }
}

2 个答案:

答案 0 :(得分:1)

自3.0以来,夹具套件有了更新 http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html

您没有实现FixturesInterface,而是扩展了Fixutres类 -

use Doctrine\Bundle\FixturesBundle\Fixture;
class LoadMovieData extends Fixture {}

答案 1 :(得分:0)

您是否尝试将Fixture附加到您的文件和类中:

AppBundle\DataFixtures\ORM\LoadMovieDataFixture.php

class LoadMovieDataFixture