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

Featured Image

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)


13 comments

  1. where to put doctrine_orm folder and which version of zend framework i need to use ?

    I am getting error ….

  2. Thanks orm-desinger looks good. But it’s a bit pricey.
    I personally use MySQL Workbench with symfony. But symfony can create schema from MySQL live database.

    Does the Zend framework can it also? By the way – are you satifsfied with choosing Zend Framework? I won’t to make flame about which framework is better. But can you write something about your feelings about Zend? Is the community helpfull? (unfortunately many of the questions over SF boards stayes unanswered) Does the Zend speeds up your developing process or does the framework issues cause more trouble then it solves?

  3. 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.

  4. 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.

  5. 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,

  6. 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.

  7. 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?

  8. 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();

  9. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.