joacub / doctrine-orm-module
Zend Framework 2 Module that provides Doctrine ORM functionality
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-10-21 13:03:51 UTC
README
DoctrineORMModule integrates Doctrine 2 ORM with Zend Framework 2 quickly and easily.
- Doctrine 2 ORM support
- Multiple ORM entity managers
- Multiple DBAL connections
- Reuse existing PDO connections in DBAL connection
Installation
Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.
php composer.phar require doctrine/doctrine-orm-module
# (When asked for a version, type `0.*`)
Then add DoctrineModule
and DoctrineORMModule
to your config/application.config.php
and create directory
data/DoctrineORMModule/Proxy
and make sure your application has write access to it.
Installation without composer is not officially supported and requires you to manually install all dependencies
that are listed in composer.json
Entities settings
To register your entities with the ORM, add following metadata driver configurations to your module (merged) configuration for each of your entities namespaces:
<?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' ) ) ) ) );
Connection settings
Connection parameters can be defined in the application configuration:
<?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', ) ) ) ), );
Full configuration options
An exhaustive list of configuration options can be found directly in the Options classes of each module.
You can find documentation about the module's features at the following links:
Registered Service names
doctrine.connection.orm_default
: aDoctrine\DBAL\Connection
instancedoctrine.configuration.orm_default
: aDoctrine\ORM\Configuration
instancedoctrine.driver.orm_default
: default mapping driver instancedoctrine.entitymanager.orm_default
: theDoctrine\ORM\EntityManager
instanceDoctrine\ORM\EntityManager
: an alias ofdoctrine.entitymanager.orm_default
doctrine.eventmanager.orm_default
: theDoctrine\Common\EventManager
instance
Command Line
Access the Doctrine command line as following
./vendor/bin/doctrine-module
Service Locator
To access the entity manager, use the main service locator:
// for example, in a controller: $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');