Last checked: ZF2.2. *, DoctrineORMModule 0.7.
Official module
You can download DoctrineORMModule through the composer:
- add
doctrine/doctrine-orm-module to your composer.json request (sample code after bcs list of formatting problems) - run
php composer.phar install - create a
./data/DoctrineORMModule/Proxy directory and provide write access for your application - configure the doctrine through your applications
/config/autoload to provide the module with project-specific settings (database, etc.) - configure the display of the essence of the doctrine in your
config.php modules - add an object to your project
- add
DoctrineORMModule and DoctrineModule to config/application.config.php - run the cli tool to create your tables
./vendor/bin/doctrine-module orm:schema-tool:create
I strongly discourage you from using the composer as this is an easy way to install dependencies and configure all autoloaders. ZF2 is also sent through the composer by default.
Code example
composer.json
{ "require" : { "php": ">=5.3.3", "zendframework/zendframework": "2.*" "doctrine/doctrine-orm-module": "0.*" } }
settings noun
<?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' ) ) ) ) );
A getcha to keep abreast of: the paths to your entites must be fully qualified. It is best to start with __DIR__ , otherwise everything will break (every new project I wonder why the command line tool does not work until I find this error ...;)
connection settings
<?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', ) ) ) ), );
All code examples are part of the official doctrine module module.
Further reading:
Marco Pivetta did , which I recommend to everyone who uses this module.
Jason Grimes wrote a tutorial presented at phpdeveloper.org, which should help establish the doctrine before the official module appeared.
Samuel Herzog Feb 01 '12 at 7:21 2012-02-01 07:21
source share