РЕДАКТИРОВАТЬ 3:
Если это имеет значение, я использую Doctrine 2.2.1. В любом случае, я просто добавляю немного больше информации по этой теме.
Я покопался в классе Doctrine \ Configuration.php, чтобы посмотреть, как newDefaultAnnotationDriver создал AnnotationDriver. Метод начинается со строки 125, но соответствующая часть - это строки от 145 до 147, если вы используете последнюю версию общей библиотеки.
} else {
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
}
Я не смог найти метод setDefaultAnnotationNamespace в классе AnnotationReader. Это было странно. Но я предполагаю, что он устанавливает пространство имен Doctrine \ Orm \ Mapping, так что аннотации в этом пространстве имен не должны иметь префикса. Отсюда и ошибка, так как кажется, что доктрина Cli Tool генерирует сущности по-разному. Я не уверен, почему это так.
В моем ответе ниже вы заметите, что я не вызывал метод setDefaultAnnotationNamespace.
С одной стороны, я заметил в вашем классе User Entity, что у вас есть use Doctrine\Mapping as ORM
. Разве созданный файл не должен создавать use Doctrine\Orm\Mapping as ORM;
? Или, может быть, это опечатка.
РЕДАКТ. 1:
Хорошо, я нашел проблему. Очевидно, это связано с драйвером аннотации по умолчанию, который используется классом \ Doctrine \ ORM \ Configuration.
Таким образом, вместо использования $config->newDefaultAnnotationDriver(...)
вам нужно создать экземпляр нового AnnotationReader, нового AnnotationDriver, а затем установить его в своем классе конфигурации.
Пример: * * тысяча двадцать-пять
AnnotationRegistry::registerFile("Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
$reader = new AnnotationReader();
$driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array(__DIR__ . "/application/persistent/Entities"));
$config->setMetadataDriverImpl($driverImpl);
EDIT2 (Здесь настройки добавлены в ваш cli-config.php):
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once 'Doctrine/Common/ClassLoader.php';
define('APPLICATION_ENV', "development");
error_reporting(E_ALL);
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__ . '/application/');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__ . '/application/persistent');
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setProxyDir(__DIR__ . '/application/persistent/Proxies');
$config->setProxyNamespace('Proxies');
$config->setAutoGenerateProxyClasses((APPLICATION_ENV == "development"));
//Here is the part that needs to be adjusted to make allow the ORM namespace in the annotation be recognized
#$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/application/persistent/Entities"));
AnnotationRegistry::registerFile("Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
$reader = new AnnotationReader();
$driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array(__DIR__ . "/application/persistent/Entities"));
$config->setMetadataDriverImpl($driverImpl);
//End of Changes
if (APPLICATION_ENV == "development") {
$cache = new \Doctrine\Common\Cache\ArrayCache();
} else {
$cache = new \Doctrine\Common\Cache\ApcCache();
}
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$connectionOptions = array(
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'dbname' => 'mydb',
'user' => 'root',
'password' => ''
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));