I would like to start developing with Zend Framework and I would like to use zf2. Since I use Doctrine 2, can you suggest some tutorials to help me to integrate it in zf2? Thanks!
last time checked: ZF2.2.*, DoctrineORMModule 0.7.
You may want to load DoctrineORMModule
via composer:
doctrine/doctrine-orm-module
to your composer.json's require (example code after list bcs of formatting problems)php composer.phar install
./data/DoctrineORMModule/Proxy
and ensure write access for your application/config/autoload
to give the module the project-specific settings (database etc)config.php
DoctrineORMModule
and DoctrineModule
to your config/application.config.php
./vendor/bin/doctrine-module orm:schema-tool:create
I strongly discourage you from not using composer, as it is an easy way to install dependencies and have the autoloaders all set up. Also ZF2 ships via composer by default.
{
"require" : {
"php": ">=5.3.3",
"zendframework/zendframework": "2.*"
"doctrine/doctrine-orm-module": "0.*"
}
}
<?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 gotcha to be aware of: The paths to your entites should be fully qualified. Best start with __DIR__
, else things will break (Every new project I wonder why the command line tool doesn't work until I find this error ... ;)
<?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 readme
Marco Pivetta made a wonderful presentation about doctrine-module usage, which I recommend to everybody using this module.
Jason Grimes wrote a tutorial featured on phpdeveloper.org which should help installing doctrine, before there was an official module.