contaoblackforest / contao-doctrine-orm
Contao CMS 的 Doctrine ORM
2.4.0
2018-09-25 22:08 UTC
Requires
- php: ^5.6 || ^7.0
- beberlei/doctrineextensions: ~1.0.0
- contao-community-alliance/composer-plugin: ^2.0
- contao-community-alliance/event-dispatcher: ^1.3
- contao/core: ^3.5.5
- contaoblackforest/contao-doctrine-dbal: ^1.2
- contaoblackforest/contao-logger: ^2.0
- doctrine/migrations: ~1.0.0
- doctrine/orm: ~2.4.1
- jdorn/sql-formatter: ~1.2
- jms/serializer: ~0.15
Requires (Dev)
- phpunit/phpunit: 3.7.*
- squizlabs/php_codesniffer: ~2.3
Conflicts
- contao-community-alliance/dc-general: <2.0.0-beta22
Replaces
- bit3/contao-doctrine-orm: 2.4.0
This package is auto-updated.
Last update: 2024-08-29 04:09:04 UTC
README
本扩展为 Doctrine ORM 提供了在 Contao Open Source CMS 中的支持。它通过服务 $container['doctrine.orm.entityManager']
提供实体管理器。要在 Contao 数据库框架中使用 Doctrine 连接,请使用 bit3/contao-doctrine-dbal-driver。
实体映射
要注册一个实体表,在您的 config.php 中添加以下内容:
$GLOBALS['DOCTRINE_ENTITIES'][] = 'orm_my_entity_type';
表名将被转换为 MyEntityType
。
可以通过将 表名前缀 映射到 类命名空间 来映射自定义命名空间
$GLOBALS['DOCTRINE_ENTITY_NAMESPACE_MAP']['orm_my_entity'] = 'My\Entity';
现在表名将被转换为 My\Entity\Type
。
在 DOCTRINE_ENTITY_NAMESPACE_MAP
用于表名转换的同时,数组 DOCTRINE_ENTITY_NAMESPACE_ALIAS
用于定义 doctrine 命名空间别名。
$GLOBALS['DOCTRINE_ENTITY_NAMESPACE_ALIAS']['My'] = 'My\Entity';
现在您可以使用 My:Type
而不是 My\Entity\Type
作为实体名称。
通过 DCA 配置实体
<?php $GLOBALS['TL_DCA']['...'] = array( 'entity' => array( // (optional) Repository class name 'repositoryClass' => 'MyEntityRepositoryClassName', // (optional) ID generator type 'idGenerator' => \Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_UUID, // (optional) Index definition 'indexes' => array( 'idx_name' => array('column_one', 'column_two', '...'), ), // (optional) Unique constraints 'uniques' => array( 'unique_name' => array('column_one', 'column_two', '...'), ), ), 'fields' => array( '...' => array( 'field' => array( 'type' => (string), // do not set fieldName! ' ), ), ), );
Contao 插件
$GLOBALS['TL_HOOKS']['prepareDoctrineEntityManager'] = function(\Doctrine\ORM\Configuration &$config) { ... }
在实体管理器创建之前调用。