根据当前配置,没有映射的Doctrine ORM实体 [英] No mapped Doctrine ORM entities according to the current configuration
问题描述
我有一个可疑的问题.我有一组现有的带注释的Doctrine实体,这些实体已在Symfony2/Doctrine2项目中成功使用.但是,我目前正在将该项目的某些核心功能隔离到它自己的独立于Web框架的库中,而且我似乎无法使实体正常工作.
I've got a dubious issue. I have a set of existing annotated Doctrine entities which have been successfully used in a Symfony2/Doctrine2 project. However, I'm currently isolating some core functionality of this project into it's own web framework independent library and I can't seem to get the entities to function properly.
目前,我最主要的担心是Doctrine CLI实用程序给我带来了混合的结果.
At the moment my major concern is the fact that the Doctrine CLI utility is giving me mixed results.
当我执行以下操作时:
bin/doctrine orm:validate-schema
我得到以下输出:
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
但是当我这样做时:
bin/doctrine orm:info
我明白了:
[Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
我现在已经遍历了数百万次的配置.我什至删除了我所有的实体,并在其中留了一个最基本的User实体,这给了我相同的情况.
I have gone over my configuration a gazillion times now. I've even removed all my entities and left a most basic User entity in there giving me the same scenario.
这些混合结果的来源可能是什么?
What could possible be the source of these mixed results?
推荐答案
事实证明,标准的Doctrine配置设置[1]不适用于我的代码库或我测试过的任何代码库,也许文档已过时.经过数小时的Interwebs工作之后,此配置终于使它对我有用:
It turns out that the standard Doctrine config set up [1] doesn't work with my code base, or any code base I have tested with, maybe the docs are outdated. After ploughing through the Interwebs for hours, this is the configuration that finally made it work for me:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationReader;
$paths = array( realpath(__DIR__."/../src/My/Entity") );
$isDevMode = TRUE;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'myuser',
'password' => 's3cr3t',
'dbname' => 'mydb',
);
$cache = new \Doctrine\Common\Cache\ArrayCache();
$reader = new AnnotationReader();
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $paths);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config->setMetadataCacheImpl( $cache );
$config->setQueryCacheImpl( $cache );
$config->setMetadataDriverImpl( $driver );
$entityManager = EntityManager::create($dbParams, $config);
//-- This I had to add to support the Mysql enum type.
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
[1] http://docs.doctrine-project .org/en/latest/tutorials/getting-started.html
这篇关于根据当前配置,没有映射的Doctrine ORM实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!