35

Possible Duplicate:
How can i inject dependencies to Symfony Console commands?

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();
0

1 Answer 1

76

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

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

Here is similar question

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks ;) I search in Symfony\Component\Console namespace, but I haven't noticed there's Symfony\Bundle\FrameworkBundle\Console and Symfony\Bundle\FrameworkBundle\Command also.
Where exactly is the 'getContainer' method defined? I can't find it on the ContainterAwareCommand..
@Luke AFAIK this answer was related to 2.0 version. Which version are you using?
I'm on 2.3. There seem to be a lot of posts on SO in regards to this and none of it seems to work. In the context of 2.3, how to you get a reference to the container? I assume you need to bootstrap a Kernel first which isn't standard procedure in a console app?
@Luke could you post a link to your code?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.