いくつかのフォームがあり、1つのカラムには Entity
タイプがありますが、このエンティティには別の接続があります。
In action i can $em->getDoctrine()->getEntityManager('name')
フォームクラスで接続を変更するには?
おそらくエンティティクラスの接続を変更する可能性があります。
このような
orm:
default_entity_manager: default
entity_managers:
owner:
connection: owner
mappings:
RealestateCoreBundle:
Entity: MyEntity
更新しました:
私はここで答えを見つけた:)
http://symfony.com/doc/2.0/reference/forms /types/entity.html#em
しかし、データフィクスチャクラスでどのように接続を変更できますか?
私は試みます:
<?php
namespace Realestate\CoreBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Realestate\CoreBundle\Entity\Owner;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OwnerFixtures implements FixtureInterface, ContainerAwareInterface
{
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public function load($manager)
{
$this->container->get('doctrine')->getEntityManager('owner');
for ($i = 0; $i < 100; $i++) {
$owner = new Owner();
$owner->setName('name-' . $i);
$owner->setTelephone(mt_rand(100000, 999999));
$manager->persist($owner);
}
$manager->flush();
}
}
しかし、仕事をしなかった:(