私はいくつかのフォームを持ち、1つのカラムにはEntity
タイプがありますが、このエンティティには別の接続があります。アクションでフォームクラスとDoctrine Fixturesでのdoctrine接続の変更
私は
$em->getDoctrine()->getEntityManager('name')
は、どのようにフォームクラスでの接続を変更することができますか?
エンティティクラスで接続を変更する可能性があります。
が、私はここに答え:)
http://symfony.com/doc/2.0/reference/forms/types/entity.html#em
を見つけました。しかし、私はデータフィクスチャクラスの接続を変更する方法:この
orm:
default_entity_manager: default
entity_managers:
owner:
connection: owner
mappings:
RealestateCoreBundle:
Entity: MyEntity
同様 が更新しますか?
は、私が試してみてください。
<?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();
}
}
しかしdidntの仕事:(
$ container-> get( 'doctrine') - > getEntityManager( 'manager_name'); ' doest work – rtyshyk
True ...あなたの什器がコンテナを認識しているかぎり、$ this-> container-> get( 'doctrine') - > getEntityManager( 'manager_name');上記のリンク。これをこのようにしたい場合は重要なビットですが、あなたのフィクスチャは 'ContainerAwareInterface'を実装しなければなりません。しかし、コマンドラインでマネージャーの名前を渡す方が簡単な方法かもしれません。 – Kasheen
更新の質問。 – rtyshyk