Symfony 4: doctrine in command

后端 未结 6 1902
[愿得一人]
[愿得一人] 2021-01-05 00:44

I am using symfony 4 and I want to access a repository for an entity if I am in the Command class. There is not a function getDoctrine or something..

I

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 01:20

    $kernel = $this->getApplication()->getKernel();
    $container = $kernel->getContainer();
    
    // Get doctrine
    $em = $container->get('doctrine')->getManager();
    

提交回复
热议问题