axelcho/laminas-orm-module

Laminas 框架模块,提供 Doctrine ORM 功能

1.0.0 2020-01-19 14:10 UTC

This package is not auto-updated.

Last update: 2024-09-24 11:38:53 UTC


README

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

这是 DoctrineORMModule 包的即插即用替代品。

安装

此模块的安装使用 composer。有关 composer 文档,请参阅 getcomposer.org

composer require axelcho/laminas-orm-module

然后,将 DoctrineModuleDoctrineORMModule 添加到您的 config/application.config.php 文件中,创建目录 data/DoctrineORMModule/Proxy 并确保您的应用程序有权写入它。

不使用 composer 的安装不受官方支持,需要您手动安装 composer.json 中列出的所有依赖项。

实体设置

要将实体注册到 ORM 中,请将以下元数据驱动程序配置添加到您的模块(合并)配置中,为每个实体的命名空间添加以下配置

<?php
return [
    'doctrine' => [
        'driver' => [
            // defines an annotation driver with two paths, and names it `my_annotation_driver`
            'my_annotation_driver' => [
                'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [
                    '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' => [
                'drivers' => [
                    // register `my_annotation_driver` for any entity under namespace `My\Namespace`
                    'My\Namespace' => 'my_annotation_driver',
                ],
            ],
        ],
    ],
];

连接设置

连接参数可以在应用程序配置中定义

<?php
return [
    'doctrine' => [
        'connection' => [
            // default connection name
            'orm_default' => [
                'driverClass' => \Doctrine\DBAL\Driver\PDOMySql\Driver::class,
                'params' => [
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'username',
                    'password' => 'password',
                    'dbname'   => 'database',
                ],
            ],
        ],
    ],
];