Integration of Doctrine2 and Zend Framework

Update: Meanwhile, Doctrine2 is stable, integration into Zend Framework has slightly changed. I have incorporated the changes into the article.

Integrating Doctrine2 into Zend Framwork (1.11) has cost me some time. Enough to write about it, and maybe make it easier for others.

The procedure is actually easy:

  1. download Zend Framework and Doctrine2

  2. create project e.g. via Zend_Tool :

    zf create project quickstart
  3. link Zend Framework and Doctrine libraries with the newly created project, either via symlink in the library folder, or just copy and paste

  4. configure web server

In case of problems with the above steps, Zend Framework's quickstart guide is recommendable. Doctrin's install guide helps with installing Doctrine2. My problem was with integrating the Doctrine2 autoloader into the Zend Framework autoloader.I was able to make it work with support from the web. First the relevant excerpt from bootstrap.php, in this context it is important that the application namespace is configured before the doctrine namespace, sources are inserted in the comments:

then you simply build a model:

and use it in an action, voila! (first create the table in the database ;) )