如何在 Symfony2 控制台应用程序中获取 Doctrine ORM 实例? [英] How to get Doctrine ORM instance in Symfony2 console application?

查看:18
本文介绍了如何在 Symfony2 控制台应用程序中获取 Doctrine ORM 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何向 Symfony 控制台命令注入依赖项?

我想制作控制台应用程序,它更改数据库中的一些记录(使用 Cron,每小时).如何在此处获取 Doctrine ORM 实例?

I want to make console application, which changes some records from the database (using Cron, every hour). How to get Doctrine ORM instance here?

在临时控制器中,我这样做:

In casual controller, I do this:

$this->getDoctrine();

推荐答案

如果你从 ContainerAwareCommand 扩展你应该能够得到你的服务

If you extend from ContainerAwareCommand you should be able to get your service

$this->getContainer()->get('doctrine');

这里是类似的问题

这篇关于如何在 Symfony2 控制台应用程序中获取 Doctrine ORM 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆