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();
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.
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.
The EntityManager is the central access point to ORM functionality. It can be used to find, persist, flush and remove entities.
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.
If you extend from ContainerAwareCommand
you should be able to get your service
$this->getContainer()->get('doctrine');
Here is similar question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With