rodchyn / doctrine-oxm-bundle
Symfony2 DoctrineOXMBundle
dev-master
2012-07-09 13:40 UTC
Requires
- php: >=5.3.2
- doctrine/oxm: master-dev
This package is auto-updated.
Last update: 2024-08-29 03:42:02 UTC
README
Doctrine OXM 是一个PHP 5.3项目,用于PHP对象到XML映射,它提供了通过常见的Doctrine技术将XML持久化到文件系统的支持。
安装
要使用OXM,您需要由Doctrine提供的OXM库以及一个将它们集成到Symfony中的包。如果您使用的是Symfony标准发行版,请将以下内容添加到项目根目录下的deps文件中
[doctrine-oxm]
git=http://github.com/doctrine/oxm.git
target=/doctrine-oxm
[DoctrineOXMBundle]
git=http://github.com/doctrine/DoctrineOXMBundle.git
target=/bundles/Doctrine/Bundle/OXMBundle
现在,通过运行以下命令来更新供应商库
$ php bin/vendors install
接下来,将Doctrine\OXM和Doctrine\Bundle\OXMBundle命名空间添加到app/autoload.php文件中,以便这些库可以被自动加载。请确保将它们添加到Doctrine命名空间(如下所示)之上
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Doctrine\\OXM' => __DIR__.'/../vendor/doctrine-oxm/lib',
'Doctrine\\Bundle' => __DIR__.'/../vendor/bundles',
// ...
));
使用OXM注解注册文件
// app/autoload.php
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine-oxm/lib/Doctrine/OXM/Mapping/Driver/DoctrineAnnotations.php');
最后,在kernel中启用新的包
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Doctrine\Bundle\OXMBundle\DoctrineOXMBundle(),
);
// ...
}
恭喜!您已经准备好开始工作了。
配置
要开始,您需要一些基本的配置来设置文档管理器。最简单的方法是启用auto_mapping,这将激活OXM在您的应用程序中
# app/config/config.yml
doctrine_oxm:
storages:
default:
path: "%kernel.root_dir%/doctrine-oxm-storage"
xml_entity_managers:
default:
auto_mapping: true
完整配置
doctrine_oxm:
proxy_namespace: Test_Proxies
auto_generate_proxy_classes: true
proxy_dir: "%kernel.cache_dir%/doctrine/oxm/Proxies"
default_xml_entity_manager: xem1
default_storage: storg1
storages:
storg1:
path: "%kernel.root_dir%/doctrine-oxm-storage/storg1"
storg2:
path: "%kernel.root_dir%/doctrine-oxm-storage/storg2"
xml_entity_managers:
xem1:
auto_mapping: false
mappings:
FooBundle: annotations
metadata_cache_driver: apc
xem2:
auto_mapping: false
storage: storg2
mappings:
BarBundle:
type: yml
dir: %kernel.cache_dir%
prefix: prefix_val
alias: alias_val
is_bundle: false
metadata_cache_driver: apc