もちろん、これを行うことができます:
public function __construct (EntityManager $em)
{
$this->em = $em;
}
必要に応じて EntityManager を使用します。しかし...カスタムクラス\サービスにスタンドアロンのEntityManagerを作成する必要があります。この方法で取得できます
public function __construct (EntityManager $em)
{
$this->em = clone $em;
}
しかし、この呼び出しが $this->em に「コピー」される前にすべてのデータが入力\追加\呼び出され、それを望まないため、これは良い選択ではありません...
質問は、(services.yml の) 引数ではなく、class\service にスタンドアロンの EntityManager を作成する方法ですか?
私はこのようなものが必要です:
public function __construct()
{
$this->em = new EntityManager()
}
アップデート:
だから私は必要な解決策を見つけました。しかし、これを EntityManager または他の「組み込み」サービスにどのように適用できますか?
http://symfony.com/doc/current/cookbook/service_container/scopes.html