I am creating entities from the database trough the \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory()
class. This works perfectly! Except for the namespace generation. There are no namespaces generated. I am storing my entities in App/Model/Entities
.
This is the code I use to generate the entities:
<?php
$em->getConfiguration()->setMetadataDriverImpl(
new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager()
)
);
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
// GENERATE PHP ENTITIES!
$entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator();
$entityGenerator->setGenerateAnnotations(true);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->generate($metadata, __dir__. '/Model/Entities");
I think, the better way is set namespace directly to driver
<?php
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager());
$driver->setNamespace('App\\Model\\Entities\\');
$em->getConfiguration()->setMetadataDriverImpl($driver);
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With