Issue
I am trying to build a batch job using command console and need to connect to DB to fetch data.
I have noticed different methods from different sections to access DB. From controller $this->getDoctrine()->getRepository()
is used and
for services it is $this->getEntityManager()->getConnection()
what is the way to connect to DB object with console component?.
Solution
If You are writing some custom console command I believe that You can just extend it to
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
and then just use
$this->getContainer()->get('doctrine')
to be in the right place.
Answered By - Vini Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.