suchen

Heim  >  Fragen und Antworten  >  Hauptteil

doctrine2 - symfony2 Ich muss eine Verbindung zu zwei verschiedenen Datenbanken herstellen.

Ich muss Daten aus zwei Datenbanken im Controller abrufen. Wie mache ich das?
http://symfony.cn/docs/cookbook/doctrine/multiple_entity_managers.html...
Ich habe nach dieser Antwort gesucht, aber nachdem ich ihr gefolgt bin, hat sie nicht funktioniert

巴扎黑巴扎黑2820 Tage vor462

Antworte allen(1)Ich werde antworten

  • 習慣沉默

    習慣沉默2017-05-16 16:46:17

    获取数据库 A 实例

    $emA = $this->get('doctrine')->getManager('default');
    

    获取数据 B 实例

    $emB = $this->get('doctrine')->getManager('customer');
    

    从 A 实例的 product 实体中取得数据

    $productsA = $emA->getRepository('AppBundle:Product')->findAll();
    

    从 B 实例的 product 实体中取得数据

    $productsB = $emB->getRepository('AppBundle:Product')->findAll();
    

    Antwort
    0
  • StornierenAntwort