noria/doctrine-orm-module

此包已被废弃,不再维护。没有建议的替代包。

提供Doctrine ORM功能的Zend Framework模块

1.1.2 2017-08-02 10:48 UTC

README

Master branch build status Scrutinizer Quality Score Code Coverage Latest Stable Version Total Downloads

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

然后,将DoctrineModuleDoctrineORMModule添加到您的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');