The DoctrineORMModule module intends to integrate Doctrine 2 ORM with Zend Framework 2 quickly and easily. The following features are intended to work out of the box:
- Doctrine ORM support
- Multiple ORM entity managers
- Multiple DBAL connections
- Support reuse existing PDO connections in DBAL
Installation of this module uses composer. For composer documentation, please refer to
getcomposer.org. To achieve the task, it currently uses OcraComposer
to integrate
your application with composer. This may change in future.
-
cd my/project/directory
-
create a
composer.json
file with following contents:{ "require": { "doctrine/DoctrineORMModule": "dev-master" } }
-
install composer via
curl -s http://getcomposer.org/installer | php
(on windows, download http://getcomposer.org/installer and execute it with PHP) -
run
php composer.phar install
-
open
my/project/directory/configs/application.config.php
and add following keys to yourmodules
(in this order)'OcraComposer', 'DoctrineModule', 'DoctrineORMModule',
-
drop
vendor/doctrine/DoctrineORMModule/config/module.doctrine_orm.local.config.php.dist
into your application'sconfig/autoload
directory, rename it tomodule.doctrine_orm.local.config.php
and make the appropriate changes. -
create directory
my/project/directory/data/DoctrineORMModule/Proxy
and make sure your application has write access to it.
Access the Doctrine command line as following
./vendor/bin/doctrine-module
Access the entity manager using the following di alias:
<?php
$em = $this->getLocator()->get('Doctrine\ORM\EntityManager');
You can also inject the EntityManager
directly in your controllers/services:
class MyController extends \Zend\Mvc\Controller\ActionController
{
public function __construct(\Doctrine\ORM\EntityManager $em) {
$this->em = $em;
// now you can use the EntityManager!
}
}