Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Doctrine ORM instance in Symfony2 console application? [duplicate]

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(); 
like image 871
pamil Avatar asked Jul 29 '12 12:07

pamil


People also ask

What is Doctrine in Symfony?

Symfony provides all the tools you need to use databases in your applications thanks to Doctrine, the best set of PHP libraries to work with databases. These tools support relational databases like MySQL and PostgreSQL and also NoSQL databases like MongoDB.

What is Doctrine db?

The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.

What is entity manager in Doctrine?

The EntityManager is the central access point to ORM functionality. It can be used to find, persist, flush and remove entities.

How does Doctrine work?

Doctrine uses the Identity Map pattern to track objects. Whenever you fetch an object from the database, Doctrine will keep a reference to this object inside its UnitOfWork. The array holding all the entity references is two-levels deep and has the keys root entity name and id.


1 Answers

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

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

Here is similar question

like image 110
Vitalii Zurian Avatar answered Sep 18 '22 16:09

Vitalii Zurian