Many reasons might cause this error but the solution is simple.


Error


Doctrine\ORM\ORMException exception "The EntityManager is closed".

The most common causes



Example solution


public function doSoemthing()
{
// ....
$this->em = $this->refreshEntityManager($this->em);
// ....
}

/**
* @param $em EntityManager
*
* @return EntityManager
*/
private function refreshEntityManager(EntityManager $em)
{
if (!$em->isOpen()) {
$em = $em->create($em->getConnection(), $em->getConfiguration());
}

return $em;
}