Symfony Doctrine can#39;t find fixtures to load(Symfony Doctrine 找不到要加载的装置)
问题描述
我从 Symfony (3.4) 开始,但负载夹具有问题.
当我执行 php bin/console dictionary:fixtures:load
然后我得到消息:
这是我的代码:
~/src/AppBundle/DataFixtures/ORM/LoadUserData.php
命名空间 AppBundleDataFixturesORM;使用 DoctrineCommonDataFixturesFixtureInterface;使用 DoctrineCommonPersistenceObjectManager;使用 SymfonyComponentDependencyInjectionContainerAwareInterface;使用 SymfonyComponentDependencyInjectionContainerInterface;类 LoadUserData 实现 FixtureInterface、ContainerAwareInterface {私人$容器;/*** 使用传递的 EntityManager 加载数据夹具** @param 对象管理器 $manager*/公共函数加载(ObjectManager $manager){$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();}公共函数 setContainer(ContainerInterface $container = null){$this->container = $container;}}
~/app/config/services.yml
参数:服务:_默认值:自动接线:真自动配置:真公开:假应用程序包:资源:'../../src/AppBundle/*'排除:'../../src/AppBundle/{Entity,Repository,Tests}'AppBundle控制器:资源:'../../src/AppBundle/Controller'公开:真实标签: ['controller.service_arguments']
谢谢.
根据您使用的夹具版本,您应该扩展/实现不同的类.如果版本 >= 3.0 则
扩展 Fixture (使用 DoctrineBundleFixturesBundleFixture;)
如果
3.0
实现 FixtureInterface, ContainerAwareInterface
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.
There is my code:
~/src/AppBundle/DataFixtures/ORM/LoadUserData.php
namespace AppBundleDataFixturesORM;
use DoctrineCommonDataFixturesFixtureInterface;
use DoctrineCommonPersistenceObjectManager;
use SymfonyComponentDependencyInjectionContainerAwareInterface;
use SymfonyComponentDependencyInjectionContainerInterface;
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
parameters:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppBundle:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
AppBundleController:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
Thanks.
Depending on what version of fixtures you use you should extend/implement different classes. If the version is >= 3.0 then
extend Fixture (use DoctrineBundleFixturesBundleFixture;)
If < 3.0
implements FixtureInterface, ContainerAwareInterface
这篇关于Symfony Doctrine 找不到要加载的装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony Doctrine 找不到要加载的装置
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01