【发布时间】:2014-09-23 06:44:45
【问题描述】:
我正在尝试更改我的实体管理器的这个结构启动以使用 Symfony 组件依赖注入。
目前正在初始化它。
$paths = array(__DIR__ . "/app/Entity/");
$isDevMode = true;
$conn = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => 'senha',
'dbname' => 'db_teste',
'host' => 'localhost',
'port' => '3306',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$cachingBackend = new \Doctrine\Common\Cache\FilesystemCache('/tmp/doctrine2');
$config->setMetadataCacheImpl($cachingBackend);
$config->setQueryCacheImpl($cachingBackend);
$config->setResultCacheImpl($cachingBackend);
$em = EntityManager::create($conn, $config);
此时我的 entitymanager 已经可以使用了。
现在我启动了我的容器。
$container = new ContainerBuilder();
但我不知道如何将 entitymanager 作为服务注入。
我已经阅读了足够多的文档,但是当我们遇到静态方法的情况时,没有说明如何做到这一点。
有人帮帮我吗?
谢谢!
【问题讨论】:
标签: symfony dependency-injection doctrine-orm entitymanager