我正在通过\Doctrine\ORM\Tools\DisconnectedClassMetadataFactory()
类从数据库创建实体。这完美!除了命名空间生成。没有生成命名空间。我将我的实体存储在App/Model/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");