Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $this->container = $this->getContainer();
- $this->getApplication()
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $entityManager = $this->getContainer()->get('doctrine')->getEntityManager();
- // Code here
- }
- $this->container = $this->getApplication()->getKernel()->getContainer();
- class UserCommand extends ContainerAwareCommand {
- private $em;
- public function __construct(?string $name = null, EntityManagerInterface $em) {
- parent::__construct($name);
- $this->em = $em;
- }
- protected function configure() {
- **name, desc, help code here**
- }
- protected function execute(InputInterface $input, OutputInterface $output) {
- $this->em->getRepository('App:Table')->findAll();
- }
- }
- class YourCmdCommand extends ContainerAwareCommand
- $em = $this->getContainer()->get('doctrine.orm.entity_manager');
- <?xml version="1.0" encoding="UTF-8" ?>
- <container xmlns="http://symfony.com/schema/dic/services"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
- <services>
- <service id="EM_NAME.entity_manager" alias="doctrine.orm.entity_manager" />
- </services>
- </container>
- $loader = new LoaderXmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('model.xml');
- $em = $this->getContainer()->get('EM_NAME.entity_manager');
- $em->flush();
- services:
- SOME_SERVICE:
- class: %parameter.class%
- arguments:
- - @EM_NAME.entity_manager
Add Comment
Please, Sign In to add comment