Symfony2: How to get Doctrine Entity Manager in Console command

symfony logoSymfony2 allow you to create your own console command thru Console Component. Since the bundle i’m writing is only for my own use, i’m trying to write a console command to load all my data to database. But to get the Doctrine entity manager to work in console command you need to do some modification from the tutorial link above. No worry i promise it’s a easy task, just edit one of the namespace will do.

To get Doctrine Manager in Console Command (Symfony2), follow the steps below:-


  • In your namespace section, look for

    and replace it with
  • Once done, you can get your Doctrine Manager thru the code below:-

Related posts:

Share this with your friends:-

One Response to “Symfony2: How to get Doctrine Entity Manager in Console command”

  1. Alex says:

    Doesn’t work in Symfony 2.3

Leave a Reply