开发者

How do you access the Doctrine service in an imported parameters file in Symfony2?

I asked a recent question about how to load your own parameters in Symfony2, which was answered here How do you load config settings from the database in Symfony2?, but I now n开发者_运维知识库eed to know how to actually access the database in the import file.

I have tried using:

$container->get('doctrine.orm.entity_manager');

Unfortunately, I then get a "The service definition doctrine.orm.entity_manager does not exist." error.

Can anyone help?


Your code should work.

$this->container->get('doctrine.orm.entity_manager');

But only if Doctrine is enabled.

Have you the Doctrine Bundle in your kernel ? Have you uncommented the doctrine settings in config.yml ?


After asking and looking around for a while the only solution I found to accessing doctrine while Symfony is still configuring its services is using this bundle. Take a look at the readme as it describes a solution to the scenario we are both experiencing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜