我需要为«复杂»系统创建灯具:涉及许多实体。
我正在使用一个使用Doctrine Fixtures的CMS,所以我选择使用可用的AbstractFixtures,允许我使用$ this-> getReference()......将一个夹具的引用传递给另一个夹具。 / p>
我followed the docs for Abstract fixtures因为我需要共享对象,然后是另一段for using container:
namespace NWA\SocBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use NWA\SocBundle\Entity\Resource\ResourceNode;
class LoadResourceData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function load(ObjectManager $manager)
{
$guid = $this->container->get('my.service.name')->generateGuid();
...
//my fixture logic here, using the value $guid at some point
}
我有错误:错误:调用成员函数get()on null
它来自哪里?
容器应该可用(因为该类实现了ContainerAwareInterface)?
----编辑----
1 - 我正在使用“doctrine / data-fixture”的“dev-master”版本
2 - 我无法看到我如何直接使用ContainerAware,因为AFAIK我不能使用多重遗产:我做不到
class LoadResourceData extends AbstractFixture, ContainerAware implements OrderedFixtureInterface
3 - 我显然不能单独使用$this->container
(没有实现ContainerAwareInterface),因为AbstractFixture不使用$this->container