No mapped Doctrine ORM entities according to the current configuration

前端 未结 4 1830
闹比i
闹比i 2021-02-04 19:31

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 isolat

4条回答
  •  轮回少年
    2021-02-04 19:48

    The accepted answer is ok but the same thing could be achieved in less verbose manner:

    use Doctrine\ORM\Tools\Setup;
    use Doctrine\ORM\EntityManager;
    
    $paths = array( realpath(__DIR__."/../src/My/Entity") );
    $isDevMode = TRUE;
    
    // the connection configuration
    $dbParams = array(
        'driver'   => 'pdo_mysql',
        'user'     => 'myuser',
        'password' => 's3cr3t',
        'dbname'   => 'mydb',
    );
    
    $config = Setup::createAnnotationMetadataConfiguration(
        $paths, $isDevMode, null, null, false
    );
    $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
    $entityManager = EntityManager::create($dbParams, $config);
    
    //-- This I had to add to support the Mysql enum type.
    $platform = $entityManager->getConnection()->getDatabasePlatform();
    $platform->registerDoctrineTypeMapping('enum', 'string');
    

    All here is about usage of simple annotation driver or not (last parameter of the Setup::createAnnotationMetadataConfiguration function. By default, a simple annotation driver is used which doesn't recognise the @ORM\Entity annotation.

提交回复
热议问题