Get array/list of entities from Doctrine

celestialorb picture celestialorb · Feb 22, 2013 · Viewed 8.9k times · Source

This is probably pretty simple, but I can't find a way to do this.

Is there any way to get a list of class names of the entities that Doctrine manages? Something like:

$entities = $doctrine->em->getEntities();

where $entities is an array with something like array('User', 'Address', 'PhoneNumber') etc...

Answer

Jack Sleight picture Jack Sleight · Apr 2, 2014

I know this question is old, but in case someone still needs to do it (tested in Doctrine 2.4.0):

$classes = array();
$metas = $entityManager->getMetadataFactory()->getAllMetadata();
foreach ($metas as $meta) {
    $classes[] = $meta->getName();
}
var_dump($classes);

Source