Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>last time checked: ZF2.2.*, DoctrineORMModule 0.7.</em></p> <h1>Official Module</h1> <p>You may want to load <code>DoctrineORMModule</code> via composer:</p> <ul> <li>add <code>doctrine/doctrine-orm-module</code> to your <em>composer.json</em>'s require (example code after list bcs of formatting problems)</li> <li>run <code>php composer.phar install</code></li> <li>create the directory <code>./data/DoctrineORMModule/Proxy</code> and ensure write access for your application</li> <li><a href="https://github.com/doctrine/DoctrineORMModule" rel="noreferrer">configure doctrine</a> via your applications <code>/config/autoload</code> to give the module the project-specific settings (database etc)</li> <li>configure doctrine's entity mapping in your modules <code>config.php</code></li> <li>add an entity to your project</li> <li>add <code>DoctrineORMModule</code> and <code>DoctrineModule</code> to your <code>config/application.config.php</code></li> <li>run the cli tool to generate your tables <code>./vendor/bin/doctrine-module orm:schema-tool:create</code></li> </ul> <p>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.</p> <h2>Example Code</h2> <h3>composer.json</h3> <pre><code>{ "require" : { "php": "&gt;=5.3.3", "zendframework/zendframework": "2.*" "doctrine/doctrine-orm-module": "0.*" } } </code></pre> <h3>entities settings</h3> <pre><code>&lt;?php return array( 'doctrine' =&gt; array( 'driver' =&gt; array( // defines an annotation driver with two paths, and names it `my_annotation_driver` 'my_annotation_driver' =&gt; array( 'class' =&gt; 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' =&gt; 'array', 'paths' =&gt; 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' =&gt; array( 'drivers' =&gt; array( // register `my_annotation_driver` for any entity under namespace `My\Namespace` 'My\Namespace' =&gt; 'my_annotation_driver' ) ) ) ) ); </code></pre> <p>A gotcha to be aware of: The paths to your entites should be fully qualified. Best start with <code>__DIR__</code>, else things will break (Every new project I wonder why the command line tool doesn't work until I find this error ... ;)</p> <h3>connection settings</h3> <pre><code>&lt;?php return array( 'doctrine' =&gt; array( 'connection' =&gt; array( // default connection name 'orm_default' =&gt; array( 'driverClass' =&gt; 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' =&gt; array( 'host' =&gt; 'localhost', 'port' =&gt; '3306', 'user' =&gt; 'username', 'password' =&gt; 'password', 'dbname' =&gt; 'database', ) ) ) ), ); </code></pre> <p><a href="https://github.com/doctrine/DoctrineORMModule/blob/master/README.md" rel="noreferrer">All code examples are part of the official doctrine module readme</a></p> <h2>Further Reading:</h2> <p>Marco Pivetta made a <a href="http://marco-pivetta.com/doctrine-orm-zf2-tutorial/#/" rel="noreferrer">wonderful presentation about doctrine-module usage</a>, which I recommend to everybody using this module.</p> <p><a href="http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/" rel="noreferrer">Jason Grimes wrote a tutorial</a> featured on phpdeveloper.org which should help installing doctrine, before there was an official module.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload