use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; require_once "vendor/autoload.php"; $paths = array("path/to/entities"); $isDevMode = false; $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); // Load models $entityManager = EntityManager::create($dbParams, $config); $models = $entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); foreach ($models as $model) { $entity = new $model(); // Do something with the entity object }
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; $entityManager = new EntityManager(...); // Load models $driver = new AnnotationDriver($annotationDirectories); $entityManager->getConfiguration()->setMetadataDriverImpl($driver); $models = $entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); foreach ($models as $model) { $entity = $entityManager->getRepository($model)->findAll(); // Do something with the entity object }This example uses the loadModels function to load all model classes defined in a specific set of annotation directories. It then retrieves all instances of each entity class from the database and processes them accordingly. The loadModels function is part of the Doctrine ORM package library.