首页 > 解决方案 > 如何将带有 EntityManager 注入的 Symfony 5 命令添加到控制台应用程序

问题描述

我在命令构造函数中添加了注入 EntityManagerInterface

# Class MyCommand
public function __construct(EntityManagerInterface $entityManager)
{
    $this->em = $entityManager;
    parent::__construct();
}

但我不明白如何将我的命令添加到应用程序,因为它现在有一个新参数

use Symfony\Component\Console\Application;

$app = new Application();
$app->add(new MyCommand($entityManager)); // where is $entityManager defined ?

如何获得定义的 $entityManager?或者我必须在某个地方定义它,因为它不能使用 Symfony 自动引导?

标签: phpsymfonydoctrine-ormsymfony5

解决方案


推荐阅读