我有一些表格,一列有Entity
类型,但是这个实体有另一个连接。更改表格类和学说夹具的学说连接
在行动,我可以$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();
}
}
但没有工作:(
其 '$ container-> get('doctrine') - > getEntityManager('manager_name');' doest work – rtyshyk
True ...它应该更像'$ this-> container-> get('doctrine') - > getEntityManager('manager_name');'只要你的夹具是容器感知的,上面的链接。如果你希望这样做,这是非常重要的,你的灯具必须实现'ContainerAwareInterface'。虽然在命令行上传递经理的名字可能是一个更简单的方法。 – Kasheen
更新问题。 – rtyshyk