如何在Symfony2控制台应用程序中获得Doctrine ORM实例? [英] How to get Doctrine ORM instance in Symfony2 console application?
本文介绍了如何在Symfony2控制台应用程序中获得Doctrine ORM实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作控制台应用程序,它从数据库中更改一些记录(使用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屋!
查看全文