2011-10-27 6 views
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 

처럼 는 UPDATED?

나는 시도 :

<?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 한 일 :(

답변

0

기구 엔티티 관리자 변경 콘솔 명령을 실행 할 때 플래그를 사용할 수로드 :

Executing Fixtures

php app/console doctrine:fixtures:load --em=manager_name 

또는이 섹션에서 확인할 수 있습니다. 전자 같은 워드 프로세서 :

당신의 고정 클래스는 컨테이너에 액세스 할 수 있습니다

Using the container in fixtures

경우에 당신은 당신이 원하는 엔티티 관리자를로드 할 수 있습니다. 당신의 고정이 config.yml에서 실제 설정과 컨테이너에 액세스 할 수있는 경우

$container->get('doctrine')->getEntityManager('manager_name'); 
+0

$ 컨테이너 -> get ('doctrine') -> getEntityManager ('manager_name'); ' doest work – rtyshyk

+0

참 ... 당신의 조명기가 컨테이너 인식을하는 한 '$ this-> container-> get ('doctrine ') -> getEntityManager ('manager_name '); 링크를 클릭하십시오. 이 방법을 원한다면 중요한 비트입니다. 당신의 조명기는 반드시'ContainerAwareInterface'를 구현해야합니다. 관리자의 이름을 명령 줄에 전달하는 것이 더 쉬운 방법 일 수 있습니다. – Kasheen

+0

업데이트 질문. – rtyshyk

0

:

$manager = $this->container->get('doctrine.orm.owner_entity_manager');

: orm: default_entity_manager: default 여기에 코드 entity_managers: owner: connection: owner mappings: RealestateCoreBundle: Entity: MyEntity

당신이 같은 엔티티 관리자를 호출 할 수 있습니다 입력

관련 문제