【发布时间】:2011-04-08 08:39:17
【问题描述】:
我试图在 Doctrine 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
【问题讨论】:
标签: php postgresql orm doctrine-orm