Ariza formasida va Doctrine Fikstürlerindeki doktrin bağlantısını değiştirin

Menda birorta shakl bor, va bitta ustun shaxsni turiga ega, lekin bu shaxs boshqa ulanishga ega.

In action i can $em->getDoctrine()->getEntityManager('name')

Ariza sinfida ulanishni qanday o'zgartirish mumkin?

Ehtimol, murojat sinfidagi aloqani o'zgartirishi mumkin. Shunga o'xshash

orm:
    default_entity_manager: default
    entity_managers:
        owner:
            connection: owner
            mappings:
                RealestateCoreBundle:
                    Entity: MyEntity

Yangilandi:

Bu erda javob topdim :)

http://symfony.com/doc/2.0/reference/forms /types/entity.html#em

Lekin axborot uzatish moslamalari sinfidagi aloqani qanday o'zgartirish mumkin?

Harakat qilaman:

<?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();
    }

}

lekin ishlamadi :(

1

2 javoblar

Fikstorlarni yuklayotganda menejerni o'zgartirish uchun konsol buyrug'ini bajarayotganda bayroqni ishlatishingiz mumkin:

Fiksturalarni bajarish

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

Shu bilan bir qatorda, ushbu bo'limni bir xil hujjatlarda tekshirishingiz mumkin:

Tarmoqdagi konteynerdan foydalanish

Agar sizning fikstür sinfingiz konteynerga kirish imkoniga ega bo'lsa, siz xohlagan istalgan menejerni yuklashingiz mumkin.

$container->get('doctrine')->getEntityManager('manager_name');
0
qo'shib qo'ydi
To'g'ri ... sizning fikstürünüz konteyner bilgan ekan, bu $ this-> container-> get ('doctrine') -> getEntityManager ('manager & zwnj; _name'); yuqoridagi havola bilan tasvirlangan. Agar shunday qilishni istasangiz, bu muhim bits, sizning arizangiz ContainerAwareInterface ni amalga oshirishi kerak. Buyruqlar satriga menejer nomini kiritish, ehtimol, oson usul.
qo'shib qo'ydi muallif Kasheen, manba
Ha, ha, men hali menejerga qaytib borishni va uni ishlatishni tayinlashingiz kerak, chunki ... $ manager = $ this-> container-> get ('doktrin') -> getEntityManager ("egasi") & zwnj ;; php-ilovasi/konsol doktrinasi bilan mos keladigan funktsiyalarni bajarishingiz mumkin: fikstürler: load --em = egasi
qo'shib qo'ydi muallif Kasheen, manba
$ container-> get ('doktrin') -> getEntityManager ("manager_name 'va zwnj;);
qo'shib qo'ydi muallif rtyshyk, manba
Savolni yangilash.
qo'shib qo'ydi muallif rtyshyk, manba

If your fixture has access to container, with your actual config in config.yml : orm: default_entity_manager: defaultenter code here entity_managers: owner: connection: owner mappings: RealestateCoreBundle: Entity: MyEntity

siz shunday korxona menejeriga qo'ng'iroq qilishingiz mumkin:

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

0
qo'shib qo'ydi