Symfony 3.4.0找不到要加载的夹具服务 [英] Symfony 3.4.0 Could not find any fixture services to load

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

问题描述

我正在使用Symfony 3.4.0,我尝试用以下方式加载灯具:

I am using Symfony 3.4.0, I try to load fixtures with:

php bin/console doctrine:fixtures:load

创建数据时发生错误,怎么了?

An error occurred while creating the data, what's wrong?

推荐答案

此命令将查找所有带有标签的服务 doctrine.fixture.orm

有两种方法可以解决此问题。

This command looks for all services tagged with doctrine.fixture.orm.
There is two ways to fix this problem.


第一个:任何实现 ORMFixtureInterface 的类都将自动为此标签注册。

First one: any class that implements ORMFixtureInterface will automatically be registered with this tag.



<?php

namespace AppBundle\DataFixtures\ORM;


use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadFixtures implements ORMFixtureInterface
{
    public function load(ObjectManager $manager)
    {
        #your code
    }
}




第二个:您需要手动在 sevice.yml doctrine.fixture.orm 标记为 DataFixtures >配置。

Second one: You need manually tag doctrine.fixture.orm to DataFixtures in sevice.yml configuration.



services:
    ...

    # makes classes in src/AppBundle/DataFixtures available to be used as services
    # and have a tag that allows actions to type-hint services
    AppBundle\DataFixtures\:
        resource: '../../src/AppBundle/DataFixtures'
        tags: ['doctrine.fixture.orm']

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

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