![](/img/trans.png)
[英]Can't run fixtures because of missing apostrophes Doctrine ? (Symfony 2)
[英]Symfony Doctrine can't find fixtures to load
我从Symfony(3.4)开始,但是负载夹具存在问题。
当我执行php bin/console doctrine:fixtures:load
我得到消息:
In LoadDataFixturesDoctrineCommand.php line 95: Could not find any fixture services to load.
有我的代码:
〜/ src / AppBundle / DataFixtures / ORM / LoadUserData.php
namespace AppBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
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}'
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
谢谢。
根据您使用的灯具版本,您应该扩展/实现不同的类。 如果版本> = 3.0,则
extend Fixture (use Doctrine\Bundle\FixturesBundle\Fixture;)
如果<3.0
implements FixtureInterface, ContainerAwareInterface
在LoadDataFixturesDoctrineCommand.php
第95行中:
找不到要加载的夹具服务。
解决方案:适用于symfony 3.4。*和doctrine-fixtures-bundle 3.0〜/ src / YC / PlatformBundle / DataFixtures / LoadCategory.php
namespace YC\PlatformBundle\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use YC\PlatformBundle\Entity\Categorie;
class LoadCategory extends Fixture
{
public function load(ObjectManager $manager)
{
$names = array(
'Développement web',
'Développement mobile',
'Graphisme',
'Integration',
'Reseau'
);
foreach ($names as $name) {
$category = new Categorie();
$category->setName($name);
$manager->persist($category);
}
$manager->flush();
}
}
〜/ src / YC / PlatformBundle / DataFixtures / LoadCategory.php
YC \\ PlatformBundle \\ DataFixtures:
resource: '%kernel.project_dir%/src/YC/PlatformBundle/DataFixtures'
tags: ['doctrine.fixture.orm']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.