Guest User

Untitled

a guest
Jan 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. $this->container = $this->getContainer();
  2.  
  3. $this->getApplication()
  4.  
  5. protected function execute(InputInterface $input, OutputInterface $output)
  6. {
  7. $entityManager = $this->getContainer()->get('doctrine')->getEntityManager();
  8.  
  9. // Code here
  10. }
  11.  
  12. $this->container = $this->getApplication()->getKernel()->getContainer();
  13.  
  14. class UserCommand extends ContainerAwareCommand {
  15. private $em;
  16.  
  17. public function __construct(?string $name = null, EntityManagerInterface $em) {
  18. parent::__construct($name);
  19.  
  20. $this->em = $em;
  21. }
  22.  
  23. protected function configure() {
  24. **name, desc, help code here**
  25. }
  26.  
  27. protected function execute(InputInterface $input, OutputInterface $output) {
  28. $this->em->getRepository('App:Table')->findAll();
  29. }
  30. }
  31.  
  32. class YourCmdCommand extends ContainerAwareCommand
  33.  
  34. $em = $this->getContainer()->get('doctrine.orm.entity_manager');
  35.  
  36. <?xml version="1.0" encoding="UTF-8" ?>
  37.  
  38. <container xmlns="http://symfony.com/schema/dic/services"
  39. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  40. xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
  41.  
  42. <services>
  43. <service id="EM_NAME.entity_manager" alias="doctrine.orm.entity_manager" />
  44. </services>
  45. </container>
  46.  
  47. $loader = new LoaderXmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  48. $loader->load('model.xml');
  49.  
  50. $em = $this->getContainer()->get('EM_NAME.entity_manager');
  51.  
  52. $em->flush();
  53.  
  54. services:
  55. SOME_SERVICE:
  56. class: %parameter.class%
  57. arguments:
  58. - @EM_NAME.entity_manager
Add Comment
Please, Sign In to add comment