Symfony2 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:-
Advertisements
- In your namespace section, look for
use Symfony\Component\Console\Command\Command;
and replace it with
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- Once done, you can get your Doctrine Manager thru the code below:-
$em = $this->getContainer()->get('doctrine')->getManager();
Related posts:
How to re-arrange account order in Thunderbird
How to setup mysqldump without password in cronjob
CPAN Error: make test had returned bad status, won't install without force
How to split compressed file into smaller files in Linux / Mac
WordPress Dev: How to send html email using wp_mail()?
How to shrink worksheet for printing in Calc - OpenOffice
How to insert new line (line break) in a cell - OpenOffice Calc
How to check if directory exists in Bash script
Share this with your friends:-
Thank you!
Doesn’t work in Symfony 2.3