joacub / doctrine-orm-module
提供 Doctrine ORM 功能的 Zend Framework 2 模块
0.11.0
2016-07-03 15:07 UTC
Requires
- php: ^5.5 || ^7.0
- doctrine/dbal: >=2.4,<2.7
- doctrine/doctrine-module: ~1.0
- doctrine/orm: >=2.5,<2.7
- symfony/console: ~2.5|~3.0
- zendframework/zend-hydrator: ^1.1
- zendframework/zend-mvc: ^2.5.2
- zendframework/zend-servicemanager: ^2.7.5 || ^3.0.3
- zendframework/zend-stdlib: ^2.7.6
Requires (Dev)
- doctrine/data-fixtures: 1.0.*
- doctrine/migrations: 1.0.*@dev
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2
- zendframework/zend-code: ^2.5.2
- zendframework/zend-config: ^2.6
- zendframework/zend-console: ^2.6
- zendframework/zend-developer-tools: ^1.0
- zendframework/zend-i18n: ^2.6
- zendframework/zend-log: ^2.5.2
- zendframework/zend-modulemanager: ^2.6.1
- zendframework/zend-serializer: ^2.6
- zendframework/zend-view: ^2.5.2
Suggests
- doctrine/migrations: doctrine migrations if you want to keep your schema definitions versioned
- zendframework/zend-developer-tools: zend-developer-tools if you want to profile operations executed by the ORM during development
- zendframework/zend-form: if you want to use form elements backed by Doctrine
This package is not auto-updated.
Last update: 2024-09-23 12:37:19 UTC
README
DoctrineORMModule 可以快速方便地将 Doctrine 2 ORM 集成到 Zend Framework 2 中。
- Doctrine 2 ORM 支持
- 多个 ORM 实体管理器
- 多个 DBAL 连接
- 在 DBAL 连接中重用现有的 PDO 连接
安装
此模块的安装使用 composer。有关 composer 文档,请参阅 getcomposer.org。
php composer.phar require doctrine/doctrine-orm-module
# (When asked for a version, type `0.*`)
然后,将 DoctrineModule
和 DoctrineORMModule
添加到您的 config/application.config.php
中,并创建目录 data/DoctrineORMModule/Proxy
,确保您的应用程序有权写入此目录。
不使用 composer 的安装不受官方支持,需要您手动安装 composer.json
中列出的所有依赖项。
实体设置
要注册实体到 ORM,请将以下元数据驱动配置添加到您的模块(合并)配置中,为每个实体命名空间中的每个实体
<?php return array( 'doctrine' => array( 'driver' => array( // defines an annotation driver with two paths, and names it `my_annotation_driver` 'my_annotation_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array( 'path/to/my/entities', 'another/path' ), ), // default metadata driver, aggregates all other drivers into a single one. // Override `orm_default` only if you know what you're doing 'orm_default' => array( 'drivers' => array( // register `my_annotation_driver` for any entity under namespace `My\Namespace` 'My\Namespace' => 'my_annotation_driver' ) ) ) ) );
连接设置
连接参数可以在应用程序配置中定义
<?php return array( 'doctrine' => array( 'connection' => array( // default connection name 'orm_default' => array( 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'user' => 'username', 'password' => 'password', 'dbname' => 'database', ) ) ) ), );
完整配置选项
配置选项的详尽列表可以直接在每个模块的选项类中找到。
有关模块功能的文档可以在以下链接中找到
注册的服务名称
doctrine.connection.orm_default
:一个Doctrine\DBAL\Connection
实例doctrine.configuration.orm_default
:一个Doctrine\ORM\Configuration
实例doctrine.driver.orm_default
:默认映射驱动程序实例doctrine.entitymanager.orm_default
:一个Doctrine\ORM\EntityManager
实例Doctrine\ORM\EntityManager
:是doctrine.entitymanager.orm_default
的别名doctrine.eventmanager.orm_default
:一个Doctrine\Common\EventManager
实例
命令行
以下是如何访问 Doctrine 命令行
./vendor/bin/doctrine-module
服务定位器
要访问实体管理器,请使用主服务定位器
// for example, in a controller: $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');