Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Keine zugeordneten Doctrine ORM-Entitäten gemäß der aktuellen Konfiguration

Es stellt sich heraus, dass die standardmäßige Doctrine-Konfiguration [1] nicht mit meiner Codebasis oder jeder Codebasis funktioniert, mit der ich getestet habe, vielleicht sind die Dokumente veraltet. Nachdem ich stundenlang das Interweb durchforstet habe, ist dies die Konfiguration, die es endlich für mich zum Laufen gebracht hat:

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