方式保持不变。
使用扩展Doctrine\ORM\EntityManager的自定义 EntityManager 类覆盖您的 services.yml 中doctrine.orm.entity_manager.class
orm.xml的参数。
覆盖创建方法(它改变了一点)
public static function create($conn, Configuration $config, EventManager $eventManager = null)
{
if ( ! $config->getMetadataDriverImpl()) {
throw ORMException::missingMappingDriverImpl();
}
switch (true) {
case (is_array($conn)):
$conn = \Doctrine\DBAL\DriverManager::getConnection(
$conn, $config, ($eventManager ?: new EventManager())
);
break;
case ($conn instanceof Connection):
if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
throw ORMException::mismatchedEventManager();
}
break;
default:
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}
// return your instance of em
return new MyEntityManager($conn, $config, $conn->getEventManager());
}
Error that you see is the fact that you have the wrong settings in the config.yml for doctrine. See reference.