我正在尝试从Docline 2.0中的Yaml加载我的架构类,而且我遇到了问题。可悲的是,Doctrine 2.0文档是ATROCIOUS。我认为Doctrine 1.2文档是废话...... 2.0只是言外之意。哇。无论如何,这是我到目前为止所拥有的:
require_once(\config\paths\CLASS_LOADER);
$loader = new \Doctrine\Common\ClassLoader('Doctrine', \config\paths\PHP_LIBRARIES);
$loader->register();
$cache = new \Doctrine\Common\Cache\ArrayCache();
$config = new \Doctrine\ORM\Configuration;
$config->setMetadataCacheImpl($cache);
$driver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(\config\paths\MODELS);
$config->setMetadataDriverImpl($driver);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(\config\paths\PROXIES);
$config->setProxyNamespace('lib\orm\proxies');
$config->setAutoGenerateProxyClasses(true);//@PRODUCTION - set this false
$connectionOptions = array(
'driver' => \config\db\DRIVER,
'user' => \config\db\LOGIN,
'password' => \config\db\PASSWORD,
'dbname' => \config\db\TABLE,
'host' => \config\db\HOST
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
所有路径都是正确的。传递给$ connectionOptions数组的所有常量都是正确的。模型路径是一个文件夹,填充了诸如ClaimStatus.dcm.yml之类的文件,其中包含以下内容:
orm\ClaimStatus:
type: entity
table: claim_status
id:
id:
type: integer
generator:
strategy: identity
fields:
name:
type: string
code:
type: string
然而,毕竟说完了,实体经理准备好了,我做了:
$em->find('orm\\Category',1);
但我得到的只是:
Warning: class_parents() [function.class-parents]: Class orm\Category does not exist and could not be loaded in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222
Fatal error: Uncaught exception 'ReflectionException' with message 'Class orm\Category does not exist' in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadata.php on line 67
答案 0 :(得分:2)
YAML驱动程序仅获取YAML文件的路径,而不是PHP类文件本身。
您需要设置一个单独的自动加载器,可以找到您的PHP类文件或手动包含它们。您可以使用Doctrine自动加载器:
$loader = new \Doctrine\Common\ClassLoader('orm', 'path/to/orm/classes');
$loader->register();