我正在使用DoctrineFixturesBundle。根据
documentation
,任何扩展的类
Fixture
将自动连接,以便控制台知道如何处理它。然而,尽管我的fixtures类扩展了
固定装置
(下面的代码),我一直收到以下错误:
找不到任何要加载的fixture服务。
如果我尝试在
services.yml
使用文件:
services:
AppBundle\DataFixtures\:
resource: '../../src/AppBundle/DataFixtures/'
tags: ['doctrine.fixture.orm']
相反,我得到:
在FileLoader中。php第168行:
/path/to/project/app/config/services中不存在文件“../../src/AppBundle/DataFixtures”(在:/path/to/project/app/config中)。yml(正在从“/path/to/project/app/config/config.yml”导入)。
在FileLocator中。php第71行:
文件“../../src/AppBundle/DataFixtures”不存在(位于:/path/to/project/app/config中)。
我的数据装置的路径是
/path/to/project/src/DataFixtures
. 实际的类文件(
AppFixtures.php
)是:
namespace AppBundle\DataFixtures;
use AppBundle\Entity\Category;
use AppBundle\Entity\Product;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
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();
}
}
为了抢先回答明显的问题,是的,捆绑包已正确注册。还有我的
服务。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
你知道我做错了什么吗?根据我找到的所有文档,这应该是可行的。