Skip to content
Zend Framework 2 Module for Doctrine ORM
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis Added support for doctrine/migrations v2 Jan 10, 2019
build Remove the license header Jan 3, 2018
config Tidy cli event hook and remove listener from config Mar 27, 2018
docs image link in documentation result in mixed content problem Mar 8, 2019
src Wrap long lines in autoload.php - PHPCS fix Jan 10, 2019
tests Use only mvc v3 configuration, as v2 is no longer supported Jan 11, 2019
view/zend-developer-tools/toolbar General code fixes Jun 2, 2017
.gitattributes [git] Add .gitattributes to remove unneeded files Jul 3, 2016
.gitignore fix lock unittest Oct 12, 2016
.scrutinizer.yml Force external code coverage Jan 5, 2015
.travis.yml Updated Travis CI configuration Jan 11, 2019
LICENSE Merge remote-tracking branch 'remotes/upstream/master' into phpunit/p… Jun 2, 2017 Update Oct 3, 2016
composer.json Updated dependencies - removed invalid conditions Jan 11, 2019
composer.lock Updated dependencies - removed invalid conditions Jan 11, 2019
phpcs.xml General code fixes Jun 2, 2017
phpunit.xml.dist ZF3 compatibility, PHP5.5 support dropped Jul 26, 2016

Doctrine 2 ORM Module for Zend Framework

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

DoctrineORMModule integrates Doctrine 2 ORM with Zend Framework quickly and easily.

  • Doctrine 2 ORM support
  • Multiple ORM entity managers
  • Multiple DBAL connections
  • Reuse existing PDO connections in DBAL connection


Installation of this module uses composer. For composer documentation, please refer to

composer require doctrine/doctrine-orm-module

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:

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' => [

            // 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',

Connection settings

Connection parameters can be defined in the application configuration:

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',

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: a Doctrine\DBAL\Connection instance
  • doctrine.configuration.orm_default: a Doctrine\ORM\Configuration instance
  • doctrine.driver.orm_default: default mapping driver instance
  • doctrine.entitymanager.orm_default: the Doctrine\ORM\EntityManager instance
  • Doctrine\ORM\EntityManager: an alias of doctrine.entitymanager.orm_default
  • doctrine.eventmanager.orm_default: the Doctrine\Common\EventManager instance

Command Line

Access the Doctrine command line as following


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::class);
You can’t perform that action at this time.