我正在使用DoctrineFixTuresBundle。根据文档,任何扩展Fixture
的类都将自动接线,以便控制台知道如何处理它。但是,尽管我的固定装置类扩展了Fixture
(下面的代码(,但我仍会遇到以下错误:
找不到加载的任何固定服务。
如果我试图在我的services.yml
文件中手动连接服务:
services:
AppBundleDataFixtures:
resource: '../../src/AppBundle/DataFixtures/'
tags: ['doctrine.fixture.orm']
我得到:
在fileloader.php行168中:
文件" ../../../src/appbundle/datafixtures"不存在(在:/path/to/to/to/to/project/project/app/config(中(正在从"/path/to/project/app/config/config.yml"中导入(。
在filelocator.php行71中:
文件" ../../src/appbundle/datafixtures"不存在(在:/path/to/to/to/to/project/app/config(。
我数据固定装置的路径是/path/to/project/src/DataFixtures
。实际的类文件(AppFixtures.php
(为:
namespace AppBundleDataFixtures;
use AppBundleEntityCategory;
use AppBundleEntityProduct;
use DoctrineBundleFixturesBundleFixture;
use DoctrineCommonPersistenceObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $em)
{
$category = new Category();
$category->setName("Test Category")
->setSlug()
->setDescription("This is only for test purposes");
$fabricProduct = new Product();
$fabricProduct->setName("Test OldProduct")
->setCanonicalPrice(2.45)
->setHasSale(false)
->setCategory($category)
->setSlug()
->setNumberInStock(45.25);
$em->persist($category);
$em->persist($fabricProduct);
$em->flush();
}
}
要先发回答明显的问题,是的,捆绑包已正确注册。我的services.yml
文件具有默认的自动功能:
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
关于我做错了什么的想法?根据我发现的所有文档,这应该有效。
解决了它...默认服务接线在Symfony中工作的方式,它希望所有内容都在src/AppBundle
目录中。我的固定装置位于该目录之外的一个目录(显然仍在项目目录中(。将我的固定装置目录作为src/AppBundle
的孩子修复。