Doctrine ORM and Zend Framework, sample project to get you started (with sample database)

10 Comments 20th APR 2009 | Posted by Branko Ajzele in Zend

Doctrine ORM and Zend Framework, sample project to get you started (with sample database)

I’ve created a sample project for those of you interested in working with Doctrine ORM and Zend Framework (my favorite toys in last few weeks). All you need to get it up n running is a download of Doctrine ORM and Zend Framework.

Project is set for auto loading both Zend and Doctrine Frameworks so all you need to do is to instantiate :) -Also, below you can see few screenshots of the sample code I implemented. Also, I provide you with the .sql dump (doctrinesql) file that goes with this project. Note the use of InnoDB engine in database. Since Doctrine comes with this cool hasOne, hasMany relation mappings, you can use bunch of cool stuff to easily do various actions on database once you get familiar with Doctrine. Although MyISAM engine is somewhat faster than InnoDB, without second thoughts I choose InnoDB due to foreign keys features.

example_user_entry

bootstrap_setup

user_class_autogenerated

article_class_autogenerated

create_new_user

add_new_user_and_new_article

add_article_for_existing_user

Download project files:
doctrinesql
doctrine_example_project (doctrine orm and zend framework)

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 10 comments (Add Yours +)

  • Great article. Everything is easy to understand and it’s a meaningful example.

    How would you add a new Article without knowing how many the user had?
    Could you simply reference it as:
    $user->Article[]->title = “Unknown number of articles”;
    etc…

    I’d be interested in seeing a version of your Zend_Auth entry redone using Doctrine.

  • I played around with your example and figured out a solution that answers my question.

    You can do something like:
    $article = new Article();
    $article->title=”whatever”;
    $article->content=”whatever”;

    $user->Article[] = $article;
    $user->save();

  • Hi, Have you tried this in a ZF1.8 enviroment? where would you put the Doctrine_Manager::Connection call in the new bootstrap class architecture?

  • Hi Will,

    In Zf 1.8 just create a resource, named for exemple “Doctrine”, and dont foreget to bootstrap it at initialization.

    Hope it will work for you.

  • Danny Froberg Says

    Will: take a look at http://www.danceric.net/2009/06/06/doctrine-orm-and-zend-framework/

    Should contain what you need I think

  • Wow, are you using Eclipse, ZF and Navicat on the Mac? If you’re running MAMP we have identical dev environments.

  • Hy,

    I have downloded ur stuff, buts it download files with no extensions, how can i use these for learning.

    Actually I am a New baby in ZF and lloking for help in configuration of ZF and atleast development of small application like the one u mentioned here, but i am not able to proceed, got stuck in, will u please help me out in this regard,

    I am keenly waiting fr ur rep, as ur above tutorial lokking helpful .
    can u plese send me this whole small working application in Zip format, so i just unzip and execute the sql to get it working.

    thnx in advance fr help

    Regards,

  • maephisto Says

    nice example. very helpfull for a beginner. thanks

  • Hi,
    Thanks for the great article. Could you please tell me what piece of software there is on the second screenshot?
    I’m also a Mac OS X user and that looks quite interesting.
    Cheers.

  • Aaiza Davidson Says

    Hi,
    thank you for this great article. It made me finally start using Doctrine and I haven’t regretted it. I can’t thank you enough for that.
    BTW: I’ve found ORM Designer (http://www.orm-designer.com/) for Doctrine which helped me a lot. It’s still under heavy development, but already deadly useful.

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009