Hello readers! The most frequently visited and linked article on my blog is by far the tutorial, how to integrate Doctrine 2 with Zend Framework 1.09. However - it is written in german and since I published it, a couple of new versions of both libraries were released. So I decided to rewrite it in english and adjust it so that it fits the most up-to-date versions of both Doctrine and the Zend Framework.

I will presume you know more or less exactly what these software packages do, and how to use them. Also, I assume that you are able to set up a virtual host by yourself. You should be familiar with how to use a command line, too!

Step 1 - Download libraries and set up the project

First of all, we need to download the libraries and set up our project. Start with the Zend Framework. Go to it’s download page and download (at least) the minimal version. Right now, it is ZF 1.11.3. Unpack the download, go to a command line (whichever your system provides), change to the bin/ folder of the package and type the following lines:

chmod +x zf.sh
./zf.sh create project /path/to/App

This is what you do on a Unix shell. It is slightly different on Windows machines, there you would have to use the zf.bat file. However, you will have to figure out how to do that on your own, since I don’t work on Windows and am too lazy to google it right now.

Your project should be created now, meaning that the folder /path/to/App should contain several subfolder such as application/, library/ and so on. We create a subfolder with the name bin/ in this folder.

What has to be done next is to move all the libraries into our project. First of all, in the downloaded package of the Zend Framework, there should be a libraries/ folder containing another folder named Zend/. We move that Zend/ folder into the library/ folder of our project.

We then go on by downloading the Doctrine packages. I say packages, because we need the Doctrine ORM as well as the DBAL and the Doctrine Commons project. Luckily, all of them are included in one package, which can be downloaded on the Doctrine ORM’s download page. It is the latest Doctrine package. (As of now, it is version 2.0.1) Unpack it and simply copy the Doctrine/ folder into our project’s library/ folder.

The last step in setting up the project is to move or copy the contents of the bin/ folders of both downloaded packages into the bin/ folder that we just created in our project.

Step 2 - The configuration file

In this tutorial, I will show how to integrate Doctrine using MySQL as database engine. The config settings might be different for other engines or when you use different database interfaces. However, we open the application/configs/application.ini of our project and insert the following lines into the [production] block of the ini file.

doctrine.conn.host = ''
doctrine.conn.user = 'root'
doctrine.conn.pass = ''
doctrine.conn.driv = 'pdo_mysql'
doctrine.conn.dbname = 'app'
doctrine.path.models = APPLICATION_PATH "/models"

At this point, you have to fill in your personal database connection settings. These might be completely different from the ones shown here. You should also adjust the database driver now, when you don’t want to use MySQL.

Step 3 - Bootstrapping

Now comes the fun part. We have to load all the Doctrine libraries and set them up correctly. To do that, we open the application/Bootstrap.php file of our project and fill it with the required functions. I will first post the whole file here and explain it below.


class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
     * generate registry
     * @return Zend_Registry
    protected function _initRegistry(){
        $registry = Zend_Registry::getInstance();
        return $registry;

     * Register namespace Default_
     * @return Zend_Application_Module_Autoloader
    protected function _initAutoload()
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Default_',
            'basePath'  => dirname(__FILE__),
        return $autoloader;

     * Initialize Doctrine
     * @return Doctrine_Manager
    public function _initDoctrine() {
        // include and register Doctrine's class loader
        $classLoader = new \Doctrine\Common\ClassLoader(
            APPLICATION_PATH . '/../library/'

        // create the Doctrine configuration
        $config = new \Doctrine\ORM\Configuration();

        // setting the cache ( to ArrayCache. Take a look at
        // the Doctrine manual for different options ! )
        $cache = new \Doctrine\Common\Cache\ArrayCache;

        // choosing the driver for our database schema
        // we'll use annotations
        $driver = $config->newDefaultAnnotationDriver(
            APPLICATION_PATH . '/models'

        // set the proxy dir and set some options
        $config->setProxyDir(APPLICATION_PATH . '/models/Proxies');

        // now create the entity manager and use the connection
        // settings we defined in our application.ini
        $connectionSettings = $this->getOption('doctrine');
        $conn = array(
            'driver'    => $connectionSettings['conn']['driv'],
            'user'      => $connectionSettings['conn']['user'],
            'password'  => $connectionSettings['conn']['pass'],
            'dbname'    => $connectionSettings['conn']['dbname'],
            'host'      => $connectionSettings['conn']['host']
        $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);

        // push the entity manager into our registry for later use
        $registry = Zend_Registry::getInstance();
        $registry->entitymanager = $entityManager;

        return $entityManager;


The first two methods don’t have anything to to with Doctrine. We just want to use a registry in our project (later, our EntityManager instance will be stored here!) and we want to register a namespace Default_ for use in our project. These methods are pure Zend Framework-ish, so I assume you know what they do. If not, consult the ZF manual.

Now for the _initDoctrine() method. The first thing we do in line 33 is to include the class loader of Doctrine. Unfortunately, Doctrine already uses the new namespacing of PHP 5 (or 6?). The Zend Framework doesn’t. So we need another class loader with the correct namespacing scheme. We set it up in the following five lines 34-38, telling it that we need the namespace Doctrine and where the include path of the library is.

We then create a Doctrine Configuration instance and configure Doctrine (lines 41-59). Depending on how you want to control the database scheme and stuff like that, you might want to adjust some of the settings here. The ArrayCache can be changed and set to something more performant and if you don’t want to use annotations in the Entities to define the database scheme, you should use a different MetadataDriver. In this tutorial, we use both the ArrayCache and the DefaultAnnotationDriver. When we instantiate the last one, we have to tell it where our classes with the annotations (I will talk about these more, later) are.

I never really understood what the Proxy classes are. They are created at runtime by Doctrine and my guess is, they are to speed up the database interaction by sort of caching joined requests. Anyways, we need to define where these classes should be saved and what namespace that is. This is done in lines 57-59.

After that, we get our connection settings from the application.ini file and can finally create the EntityManager instance by telling it all our configurations and connection information. ThisEntityManager can be understood as the interface between the Database and our models (called Entities). We are saving it’s instance in the Zend Registry we created earlier.

And that’s it. We can now start creating Entities (models) and trying to do some database interaction!

Step 4 - The Entity

To test everything, we create a small dummy Entity. I will not go into detail on how to create Entites and define the database scheme of their tables. As we defined in the Doctrine config earlier, we want to use annotations (in the Docblock of our Entity) to define the database scheme. We create a file application/models/Test.php and fill it with the following code:


 * @Entity
 * @Table(name="test123")
class Default_Model_Test
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
    private $id;

    /** @Column(type="string") */
    private $name;

    public function setName($string) {
        $this->name = $string;
        return true;

As you see, we want a models with the fields id and name, id being an integer and auto_incremented and name being a string. The table name is set to test123. As you can see, an Entity is nothing more than a PHP class with some members and methods. Only the definitions for how Doctrine should build the table have to be given in the annotations. You could as well use YAML or XML files to define these.

The next step is to adjust the command line tool of Doctrine to fit into our project.

Step 5 - the command line tool

Simply copy the following code into bin/doctrine.php replacing all of the code already in the file.


define('APPLICATION_ENV', 'development');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),

// Doctrine and Symfony Classes
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', APPLICATION_PATH . '/../library');
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', APPLICATION_PATH . '/../library/Doctrine');
$classLoader = new \Doctrine\Common\ClassLoader('Entities', APPLICATION_PATH . '/models');

// Zend Components
require_once 'Zend/Application.php';

// Create application
$application = new Zend_Application(
    APPLICATION_PATH . '/configs/application.ini'

// bootstrap doctrine
$em = $application->getBootstrap()->getResource('doctrine');

// generate the Doctrine HelperSet
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)


We do some bootstrapping of our project here to obtain the EntityManager instance. We then create a HelperSet with the EntityManager and run the cli tool.

To create our database table based on the Entity we created earlier, we open a command line, change into the bin/ folder of our project and run

chmod +x ./doctrine
./doctrine orm:schema-tool:create

Again, this is for the Unix shell and is different on Windows machines! Fire up your favourite database administration tool and have a look! The table test123 should have been created properly.

Step 6 - Using the database

I will just post a small example of how to use everything. Replace the content of your application/controllers/IndexController.php with the following:


class IndexController extends Zend_Controller_Action
    public function init()
        $registry = Zend_Registry::getInstance();
        $this->_em = $registry->entitymanager;

    public function indexAction()
        $testEntity = new Default_Model_Test;
        $testEntity->setName('Zaphod Beeblebrox');


This is just some quick and dirty dummy code to check if everything works. We get our EntityManager out of the registry and save it as a member of the Controller. We then create a new model (Entity), set the name and by using the EntityManager‘s persist method, we save it. EntityManager->flush() actually invokes the database action and the row should occur in our table.

Test this by simply browse to your project in your favourite webbrowser. If everything worked fine, the table should now have one entry with the name Zaphod Beeblebrox.

If anything did not work, feel free to ask in the comments here! I will be glad to answer any questions.

<section id="comments" class="comment-list"><h1>Comments</h1><ul> <li class="comment"> <div class="head"> <span class="author">Doctrine 2 ins Zend Framework 1.9 integrieren &amp;laquo; Oli&amp;#039;s 2 cents</span> <span class="date">Feb. 19, 2011, 6:05 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-36">reply</a> </span> </div> <div class="text"><p>[&hellip;] I rewrote this tutorial in english and adjusted it to fit to the newest version of Doctrine and the Zend Framework. Check it out here! [&hellip;]</p></div> </li> <li class="comment"> <div class="head"> <span class="author">David</span> <span class="date">Feb. 20, 2011, 12:49 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-37">reply</a> </span> </div> <div class="text"><p>Great Tutorial. Works flawless :)</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Feb. 20, 2011, 5:59 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-38">reply</a> </span> </div> <div class="text"><p>Thanks. :)</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Another David</span> <span class="date">Feb. 25, 2011, 9:28 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-39">reply</a> </span> </div> <div class="text"><p>Thanks alot! Very good and working tutorial. Just to spare the windows users a few seconds:</p> <p>Windows console commands:<br /> [create the project] zf create project C:\path o\App<br /> [create schema] php doctrine orm:schema-tool:create</p> <p>Not very different huh? ;-)</p> <p>Tanks again,<br /> David</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Dojo Man</span> <span class="date">Aug. 2, 2012, 11:55 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-102">reply</a> </span> </div> <div class="text"><p>New to ZF</p> <p>I get the could not open input file: doctrine</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Kevin Pabst</span> <span class="date">March 3, 2011, 3:32 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-40">reply</a> </span> </div> <div class="text"><p>Hi Jan!<br /> Thanks for the great tutorial. It made the first steps very easy. <br /> Now I have to reverse engineer my models, as I do not see an option to generate them from my metadata files (which I could easily generate using your CLI script from an existing database).</p> <p>Very good stuff - thanks a lot!<br /> Kevin</p></div> </li> <li class="comment"> <div class="head"> <span class="author">John</span> <span class="date">March 4, 2011, 10:14 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-41">reply</a> </span> </div> <div class="text"><p>Thank you very much, your post is very helpful and much detail than official tutorial. <br /> I just have one question: In my Zend Studio, if I typed \Doctrine\Common\ it always display <br /> &lsquo;syntax error, unexpected &lsquo;Common&rsquo; Bootstrap.php /FaceTrade/application line 34 DLTK Problem&rsquo; and some similar error tips. I do have move Doctrine into /library<br /> doctrine.php can be successfully executed. Just not sure why the Zend Studio not work with this namespace. thanks.</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Kevin Pabst</span> <span class="date">March 4, 2011, 10:27 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-42">reply</a> </span> </div> <div class="text"><p>@John: I experienced the same problem. Right click on project =[HTML_REMOVED] Properties =[HTML_REMOVED] PHP Interpreter and change it to PHP 5.3. Default was 5.1/5.2 for me.</p> <p>Just in case someone is interested. To get rid of the nasty Registry, you can also use this in your controller to fetch the Entitymanager:</p> <p>$entityManager = $this-[HTML_REMOVED]getInvokeArg(&lsquo;bootstrap&rsquo;)-[HTML_REMOVED]getResource(&lsquo;Doctrine&rsquo;);</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">March 5, 2011, 9:07 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-43">reply</a> </span> </div> <div class="text"><p>The Registry is not nasty but a very useful tool to exchange every kind of variables/instances within the application&hellip; :P</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Jeanpaul</span> <span class="date">March 14, 2011, 3:08 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-44">reply</a> </span> </div> <div class="text"><p>Thanks, I was looking for a zf + doctrine 2 tutorial. I have a question though, In step 1 you mention a <code>bin/ folder that we just created in our project</code>. Do i create it manually, and where in the dir. structure should it be, or should it have been created by the zf create project command?</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">March 14, 2011, 6:16 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-45">reply</a> </span> </div> <div class="text"><p>Hi Jeanpaul, I wrote the following before:</p> <p>&ldquo;Your project should be created now, meaning that the folder /path/to/App should contain several subfolder such as application/, library/ and so on. We create a subfolder with the name bin/ in this folder. &ldquo;</p> <p>Note, that the bin/ folder and the files that are created and copied there are only needed, if one needs to use the command line tools from Zend Framework or doctrine. I never use the former, but I like the doctrine cli tool and use it a lot.</p> <p>With some minor changes in the code, you could place the bin/ folder whereever you want, it is not needed for your website to run.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Charlie</span> <span class="date">Aug. 24, 2012, 2:07 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-105">reply</a> </span> </div> <div class="text"><p>Hi Oli,</p> <p>I&rsquo;m just beginning to use ZF and doctrine. I set up ZF so that I can use the zf command anywhere. I would like to try to do that with Doctrine but it seems to me that it might not be possible because the Doctrine.php is rewritten.</p> <p>could you, please, help me with this?. appreciate the help.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Aug. 24, 2012, 10:10 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-106">reply</a> </span> </div> <div class="text"><p>Hi Charlie, I&rsquo;m sorry, I don&rsquo;t really get what you mean. However, I recommend updating to Zend Framework 2 and using the built-in Doctrine support. This should be much cleaner and universally useable than my tutorial.</p> <p>Also, I didn&rsquo;t touch the ZF for years now and am currently forgetting all about it. :(</p></div> </li> </ul> </ul> </ul> <li class="comment"> <div class="head"> <span class="author">Jeanpaul</span> <span class="date">March 14, 2011, 6:48 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-46">reply</a> </span> </div> <div class="text"><p>Thanks for the info. I thought there was something wrong with the path of the bin directory. The errors i recieved were actually due to the fact that i was trying to run the doctrine command on php 5.2 instead of php 5.3 so i ran into namespaces problems :-)</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Samuel</span> <span class="date">April 13, 2011, 3:39 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-47">reply</a> </span> </div> <div class="text"><p>Hi Oli, thanks a lot for your great tutorial.<br /> But I have a problem now, and I really don&rsquo;t know what it is.<br /> The table test123 was created succesfully, but I can&rsquo;t create a row inside with the entity manager. I&rsquo;d appreciate any suggestions.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">April 13, 2011, 6:22 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-48">reply</a> </span> </div> <div class="text"><p>Hi Samuel, did you maybe forget to flush the entity manager?</p> <p>The persist() function does not actually execute the database queries, just kind of qeues them. They are executed when the flush() method of the Entity Manager is called.</p> <p>If you did do that, can you provide any error message?</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Samuel</span> <span class="date">April 13, 2011, 7:20 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-49">reply</a> </span> </div> <div class="text"><p>Hi Oli.<br /> It&acute;s kind of weird. I did all what you&rsquo;ve said. Of course I had flushed the entity manager, and when I executed the explorer no error messages appeared.<br /> I can see my view, but I don&acute;t get the new row in the table.<br /> My doctrine.php is fine, because I can generate my table. Then I can assume that my bootstrap.php isn&rsquo;t fine. &iquest;?<br /> Any Ideas?</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Samuel</span> <span class="date">April 13, 2011, 7:51 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-50">reply</a> </span> </div> <div class="text"><p>Hi Oli.</p> <p>I&acute;ve solved. Thanks a lot.</p> <p>Greetings.</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Andy</span> <span class="date">April 18, 2011, 7:02 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-51">reply</a> </span> </div> <div class="text"><p>Oli,</p> <p>Any chance you could zip this up into a stand alone application?</p> <p>I&rsquo;m thinking this shouldnt be v. difficult, that way i can see a little more what is happening.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">April 18, 2011, 7:08 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-52">reply</a> </span> </div> <div class="text"><p>Hi Andy,</p> <p>I thought about this already, but I am very unsure about if I am allowed to redistribute ZF and Doctrine libraries. </p> <p>It might be allowed, but before I would do anything like this, I would read the licenses carefully. </p> <p>I will have a look tomorrow, maybe it&rsquo;s easier than I thought. If so, I will provide a download soon.</p> <p>Regards</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Andy</span> <span class="date">April 18, 2011, 7:20 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-53">reply</a> </span> </div> <div class="text"><p>Oli,</p> <p>Thanks for this, i only ask because i&rsquo;m getting:</p> <p>===================</p> <p>PHP Warning: Unexpected character in input: &rdquo; (ASCII=92) state=1 in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31</p> <p>Warning: Unexpected character in input: &rdquo; (ASCII=92) state=1 in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31<br /> PHP Warning: Unexpected character in input: &rdquo; (ASCII=92) state=1 in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31</p> <p>Warning: Unexpected character in input: &rdquo; (ASCII=92) state=1 in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31<br /> PHP Parse error: syntax error, unexpected T_STRING in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31</p> <p>Parse error: syntax error, unexpected T_STRING in C:\workspace\ToDoList\library\Doctrinein\doctrine.php on line 31</p> <p>===================</p> <p>Clearly something is wrong, i&rsquo;m copying and pasting from within here, maybe it&rsquo;s a chat encoding issue? I will try and work out what&rsquo;s happening myself, but so far so annoying :)</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Andy</span> <span class="date">April 18, 2011, 7:21 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-54">reply</a> </span> </div> <div class="text"><p>Oh and clearly i&rsquo;m working within windows. Annoyingly, this also needs to work with Linux. I&rsquo;m thinking it&rsquo;s probably because doing \Common will escape the C?</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Andy</span> <span class="date">April 18, 2011, 8:04 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-55">reply</a> </span> </div> <div class="text"><p>Ha, so, it turns out i wasnt using the correct version of PHP. As we know Doctrine 2.0 works on at least 5.3 i was trying to do this on v.5.2.6 hence the fail.</p> <p>I&rsquo;m now getting a different error so all in all i&rsquo;m starting to make progress. Thanks Oli will update if i need more help.</p></div> </li> </ul> </ul> <li class="comment"> <div class="head"> <span class="author">Guilherme Blanco</span> <span class="date">April 30, 2011, 5 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-56">reply</a> </span> </div> <div class="text"><p>Hi,</p> <p>I have worked on an integration of ZF 1.X + D 2.X some time ago and I use it daily. =)<br /> Here is the github repository: https://github.com/guilhermeblanco/ZendFramework1-Doctrine2</p> <p>Also, for better separation of concerns, I also implemented a Service Layer at the top of this integration: https://github.com/guilhermeblanco/ZF1-Doctrine2-ServiceLayer</p> <p>Hope it helps.</p> <p>Cheers,</p> <p>Guilherme Blanco - Doctrine Core Developer</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">April 30, 2011, 11:19 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-57">reply</a> </span> </div> <div class="text"><p>That indeed looks a lot more elegant than my approach, even though my code might be easier to understand for non-experts. (like me. :) )</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Mahesh</span> <span class="date">May 2, 2011, 4:21 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-58">reply</a> </span> </div> <div class="text"><p>Hi Oli,</p> <p>Thanks a lot for your great tutorial. every thing is working fine for me.</p> <p>I am requesting post one example to get the data from table test123. Can u provide it. it will help full for all beginners like me.</p> <p>Thanks,<br /> Mahesh</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">May 2, 2011, 5:42 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-59">reply</a> </span> </div> <div class="text"><p>Dear Mahesh,</p> <p>You can find an introduction on how to query the database here: http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/getting-started-xml-edition.html#list-of-bugs</p> <p>The DQL (doctrine query language) is a bit complex, so you might want to read the reference to be able to use it efficiently. This tutorial&rsquo;s purpose is rather to integrate doctrine within the ZF and not how to use Doctrine. That is explained very well in the Doctrine documentation.</p> <p>Best regards, Oli</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oleg</span> <span class="date">July 15, 2012, 1:43 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-98">reply</a> </span> </div> <div class="text"><p>I tried to use your advice, but I can&rsquo;t select data. I don&rsquo;t know why. Can you help me, please?<br /> public function action2Action()<br /> {<br /> $dql = &ldquo;SELECT * FROM test123&rdquo;;</p> <p>$query = $this-[HTML_REMOVED]_em-[HTML_REMOVED]createQuery($dql);<br /> $bugs = $query-[HTML_REMOVED]getResult();<br /> }</p> <p>I get an error on the last line of action(Application error).</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oleg</span> <span class="date">Aug. 17, 2012, 9:39 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-104">reply</a> </span> </div> <div class="text"><p>It was my error, but there is no one guide in network, which give me all info I want. It took me much time to get this info from different sources.</p></div> </li> </ul> </ul> </ul> <li class="comment"> <div class="head"> <span class="author">Mohammed Meabed</span> <span class="date">May 7, 2011, 6:22 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-60">reply</a> </span> </div> <div class="text"><p>This is perfect :) thank you [HTML_REMOVED]3</p></div> </li> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 7, 2011, 6:36 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-61">reply</a> </span> </div> <div class="text"><p>Hi Oli, <br /> Thanks a lot, BUT there is something i want to ask you.<br /> 1. In your test.php, you use:<br /> class Default_Model_Test as name of your class.<br /> and in your indexAction you write:<br /> $testEntity = new Default_Model_Test; to insert new record.<br /> How should i use this method to query a record? Should i write:<br /> $testEntity = new \Default_\Test;<br /> $result = _em-[HTML_REMOVED]getRepository($testEntity)-[HTML_REMOVED]findOneByName(&lsquo;abc&rsquo;); ???<br /> but it didn&rsquo;t work.<br /> Please help me how to make a query? Or please help me with FQCN or Entity or How to instantiate a class from files in the model folder.</p> <ol> <li>What is the purpose of namespace Default_ ???</li> </ol> <p>Thanks in advance<br /> Your tutorial does help me so much.</p> <p>Best Regards</p> <p>Or there</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">May 7, 2011, 11:50 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-62">reply</a> </span> </div> <div class="text"><p>Dear seferina,</p> <p>Try $testEntity = new Default_Model_Test();</p> <p>This is how the namespacing works in ZF. The \x\y\class.php pattern is not yet supported by the ZF autoloaders.</p> <p>The purpose of Default_ is, that you just have to assign some namespace name when you instantiate your autoloader. I used Default_, but usually you will use a name that fits your part of the software. So if you had some community software, you would probably have a namespace for Forum_ and one for Profile_ and so on. Different &ldquo;apps&rdquo; should be assigned different namespaces in general.</p> <p>Regards, Oli</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 8, 2011, 5:35 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-63">reply</a> </span> </div> <div class="text"><p>Hi Oli, <br /> Thanks for your prompt replay.<br /> I still have no idea hhow to make a query using under score way to instantiate class.<br /> I read on WJGILMORE page wjgilmore.com that he can instantiate class by using:<br /> $testEntity = New \Entities\Test; and to make a query he can write:</p> <p>$testEntity = $em-[HTML_REMOVED]getRepository(&lsquo;Entities\Test&rsquo;)<br /> -[HTML_REMOVED]findOneByUsername(&lsquo;abc&rsquo;);</p> <p>If I use Default_Model_Test, then i have no idea how to make a query to the table. Please help&hellip; </p> <ol> <li>In your tutorial, You use Default_ as a namespace, so to instantiate class you use &ldquo;Default_&rdquo; as a prefix, $testEntity = New Default_Model_Test();<br /> Is it possible if I use namespace tag in my test.php, like this:</li> </ol> <p>name = $string;<br /> return true;<br /> }<br /> }</p> <p>Oli, Many many thanks with the tutorial and support.<br /> I appreciated so much. It helps me learn doctrine and ZF.<br /> Best Regards</p> <p>SF</p></div> </li> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 8, 2011, 6:04 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-64">reply</a> </span> </div> <div class="text"><p>Hi Oli, <br /> Sorry, for question number 2, it should be like this:</p> <p>name = $string;<br /> return true;<br /> }<br /> }</p> <p>Is it possible to write the namespace like that.<br /> Thanks and Regards</p></div> </li> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 8, 2011, 6:06 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-65">reply</a> </span> </div> <div class="text"><ol> <li>In your tutorial, You use Default_ as a namespace, so to instantiate class you use &#147;Default_&#148; as a prefix, $testEntity = New Default_Model_Test();<br /> Is it possible if I use namespace tag in my test.php, like this:</li> </ol> <p>namespace Default_<br /> /<strong><br /> * @Entity<br /> * @Table(name=&rdquo;test1234&rdquo;)<br /> */<br /> class Model_Test<br /> {<br /> /</strong><br /> * @Id @Column(type=&rdquo;integer&rdquo;)<br /> * @GeneratedValue(strategy=&rdquo;AUTO&rdquo;)<br /> */<br /> private $id;</p> <div class="codehilite"><pre><span class="cm">/** @Column(type="string") */</span> <span class="n">private</span> <span class="err">$</span><span class="n">name</span><span class="p">;</span> <span class="n">public</span> <span class="k">function</span> <span class="n">setName</span><span class="p">(</span><span class="err">$</span><span class="k">string</span><span class="p">)</span> <span class="p">{</span> <span class="err">$</span><span class="k">this</span><span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span><span class="n">name</span> <span class="o">=</span> <span class="err">$</span><span class="k">string</span><span class="p">;</span> <span class="k">return</span> <span class="n">true</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">May 8, 2011, 8:14 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-66">reply</a> </span> </div> <div class="text"><p>Dear seferina.</p> <p>It might have been wrong of me to use the word namespace, since ZF does NOT know what namespaces are and how to handle it in the PHP way. So forget all about these backslashes. The namespace functionality will be introduced in ZF 2.0. Now, ZF defines some pattern for autoloading of classes; Default_Model_Something() is translated by the autoloader into Default/Model/Something.php and the class really is named Default_Model_Something(). So whenever you want to use it, you will have to use the full classname.</p> <p>$testEntity = new Default_Model_Test();<br /> $result = $_em-&gt;getRepository($testEntity)-&gt;findOneByName(&lsquo;abc&rsquo;);</p> <p>does not work? <br /> When you want to query it is usually better to use doctrines DQL language. Here is an example: http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/getting-started-xml-edition.html#list-of-bugs There, just use Default_Model_Test() as table name and it should work.</p> <p>I used the word namespace because using Default_ we introduce a &ldquo;quasi-namespace&rdquo; since all of our classes that belong to Default_ share one folder. But it might be easier for you to forget about namespaces right now. Just trsut ZF to load the correct classes and use the full classname whenever you want to utilize them.</p> <p>Regards</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 8, 2011, 12:34 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-67">reply</a> </span> </div> <div class="text"><p>Hi Oli.<br /> Thanks for the prompt replay. I still need to learn to understand it all.<br /> 1. About namespace, It is avaible on the bootstrap.php, so it must be important.<br /> $autoloader = new Zend_Application_Module_Autoloader(array(<br /> &lsquo;namespace&rsquo; =[HTML_REMOVED] &lsquo;Default_&rsquo;,<br /> &lsquo;basePath&rsquo; =[HTML_REMOVED] dirname(<strong>FILE</strong>),<br /> ));<br /> return $autoloader;</p> <ol> <li> <p>In this link, http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/getting-started-xml-edition.html#list-of-bugs<br /> On the , Entity Repository part:</p> <p>$product = $entityManager-[HTML_REMOVED]getRepository(&lsquo;Product&rsquo;)<br /> -[HTML_REMOVED]findOneBy(array(&lsquo;name&rsquo; =[HTML_REMOVED] $productName));<br /> Where should the &ldquo;Product&rdquo; php class file reside? Under Application\Model\product.php or where ??</p> </li> </ol> <p>Many Thanks, I will read more carefully, to understand it.<br /> Thanks a lot Oli.</p> <p>Best Regards<br /> SF</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">May 8, 2011, 2:47 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-69">reply</a> </span> </div> <div class="text"><p>getRepository() expects the entityname, that is the classname of the php class.</p> <p>so $result = $_em-&gt;getRepository(&ldquo;Default_Model_Test&rdquo;)-&gt;findOneByName(&ldquo;abc&rdquo;);</p> <p>should work just fine. I explained in an earlier comment why I will not explain in this article how to use Doctrine, since that is not the purpose of this tutorial.</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">seferina</span> <span class="date">May 8, 2011, 12:52 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-68">reply</a> </span> </div> <div class="text"><p>Hi Oli, <br /> I will be very appreciated if you can give us an example how to make a query using previous configuration (use test.php), but not to insert, but to quesry a record and display it.</p> <p>I am waiting your post for that example.<br /> Many many thanks Oli.</p> <p>Best Regards<br /> SF</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Ben</span> <span class="date">June 8, 2011, 11:17 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-70">reply</a> </span> </div> <div class="text"><p>Oli,<br /> thanks for your wonderful description. It worked very well.<br /> I have now a new challenge, where I can&rsquo;t find an answer by myself.<br /> I want to use a @InheritanceType(&ldquo;SINGLE_TABLE&rdquo;) for which I need to specify the inheriting classes in Zend naming convention.<br /> Unfortunetly the command tool can&rsquo;t find the corresponding file anymore.<br /> Can you point me in a direction? I have tried now a couple of hours, but I still don&rsquo;t understand the relationship between doctrine namespaces and Zend naming convention.<br /> Thanks,<br /> Ben</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Ben</span> <span class="date">June 9, 2011, 10:21 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-71">reply</a> </span> </div> <div class="text"><p>Ok, I was able to find a work-around.<br /> The problem was that I wanted my models to be in my module directory. But the command line tool didn&rsquo;t find inheriting classes anymore. <br /> I moved now the models to the library and use proper namespaces. Now it works!<br /> But I still have problems to understand the class loading and namespaces, especially when it comes to modules.<br /> Thanks anyway,<br /> Ben</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">June 9, 2011, 11:58 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-72">reply</a> </span> </div> <div class="text"><p>Dear Ben, I am glad you solved your issue. I am sorry that I didn&rsquo;t reply, but I haven&rsquo;t seen the comment yet. I guess I wouldn&rsquo;t have been able to answer the question anyway.<br /> Thanks for sharing,<br /> Oli</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">cuong.ngo</span> <span class="date">June 10, 2011, 10:47 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-73">reply</a> </span> </div> <div class="text"><p>Great tutorial. It work for me!<br /> Thank you very much</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Fred</span> <span class="date">June 15, 2011, 10:19 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-74">reply</a> </span> </div> <div class="text"><p>Perfect tutorial. Especially for newbie like me&hellip;<br /> Thanks a lot&hellip;</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Matthew Wakeham</span> <span class="date">July 8, 2011, 12:55 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-75">reply</a> </span> </div> <div class="text"><p>Thank you, Thank you, Thank you. I have finally found someone who can make doctrine work perfectly.<br /> I look forward to reading more of your Zend Framework tutorials</p></div> </li> <li class="comment"> <div class="head"> <span class="author">anith</span> <span class="date">July 18, 2011, 11:12 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-76">reply</a> </span> </div> <div class="text"><p>Thank you for this great tutorial. The best I found in the Web! I red many of them, they didn&rsquo;t want to work for me&hellip;</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Zend Framework Doctrine 2 Entegrasyonu</span> <span class="date">July 21, 2011, 2:37 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-77">reply</a> </span> </div> <div class="text"><p>[&hellip;] Kaynak : http://www.oelerich.org/?p=315 [&hellip;]</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Robert</span> <span class="date">Aug. 3, 2011, 10:04 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-78">reply</a> </span> </div> <div class="text"><p>Thank you! Took me a few minutes to get it work using this tutorial.</p></div> </li> <li class="comment"> <div class="head"> <span class="author">astha</span> <span class="date">Sept. 8, 2011, 7:20 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-79">reply</a> </span> </div> <div class="text"><p>can someone tell me how to integrate doctrine 2.1.1 with zend framework???? plzzzz</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Sept. 15, 2011, 7:31 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-82">reply</a> </span> </div> <div class="text"><p>It shouldn&rsquo;t be that different from Doctrine 2.0.x, right? What about you try it yourself and share the results? :)</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">devta</span> <span class="date">Sept. 15, 2011, 12:15 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-80">reply</a> </span> </div> <div class="text"><p>Hi, <br /> This is so far the best, and the easiest to understand, tutorial I have found. Great work! </p> <p>But just wondering if your tutorial will work if we have doctrine 1.1.2 and php 5.2.14? If not, what changes we might need to do to make it compatible.</p> <p>cheers</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Sept. 15, 2011, 7:30 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-81">reply</a> </span> </div> <div class="text"><p>Hello devta, I started out with Doctrine 1 back then and there is plenty of tutorials on the internet how to integrate it with ZF. The Zend Framework didn&rsquo;t change that much, so just try to find something via google.</p> <p>Regards</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Integrate Doctrine 2.0.1 with Zend Framework 1.11.3 « Oli&amp;#039;s 2 cents - EtondeGroup Blog of Web Applications | EtondeGroup Blog of Web Applications</span> <span class="date">Dec. 15, 2011, 7:25 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-83">reply</a> </span> </div> <div class="text"><p>[&hellip;] the original: Integrate Doctrine 2.0.1 with Zend Framework 1.11.3 &laquo; Oli[HTML_REMOVED]s 2 cents Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers [&hellip;]</p></div> </li> <li class="comment"> <div class="head"> <span class="author">chris2011</span> <span class="date">Dec. 20, 2011, 10:32 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-84">reply</a> </span> </div> <div class="text"><p>On windows with ZendFramework 1.11 + Doctrine 2.1.5</p> <p>i get this error :</p> <p>[pdoexception] SQLSTATE[42000] [1049] unknown database &lsquo;app&rsquo;</p> <p>I should mention that &ldquo;app&rdquo; database is already created with PhpAdmin on Wampserver 2.0. </p> <p>So, where should i look for in order to fix it ?</p> <p>Thanks</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">chris2011</span> <span class="date">Dec. 21, 2011, 8:12 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-85">reply</a> </span> </div> <div class="text"><p>well, it turns out i only had to change this line</p> <p>doctrine.conn.host = &lsquo;; </p> <p>into this :</p> <p>doctrine.conn.host = &lsquo;localhost&rsquo; </p> <p>Tnen run this command from my command prompt (i&rsquo;m on windows)after navigating to &ldquo;bin&rdquo; folder :</p> <p>php doctrine orm:schema-tool:create</p> <p>Indeed it creates the empty table test123 into the already created database &lsquo;app&rdquo;</p> <p>After that, in my browser, i go to </p> <p>http://localhost/testdoctrine/public/ </p> <p>which appends that record into test123 table. <br /> (testdoctrine is, of course, the project folder on my computer)</p> <p>Good tutorial</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Doctrine 2 ve Zend Framework Entegrasyonu | Geli?tirici Günlü?ü</span> <span class="date">Dec. 25, 2011, 10:29 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-86">reply</a> </span> </div> <div class="text"><p>[&hellip;] ?imdi Base namespace i alt?na Bootstrap.php dosyas?n? olu?turuyorum.(Burada implementasyon i&ccedil;in kaynak : http://www.oelerich.org/integrate-doctrine-2-with-zend-framework-1-11-3/ [&hellip;]</p></div> </li> <li class="comment"> <div class="head"> <span class="author">sepp</span> <span class="date">Dec. 30, 2011, 3:50 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-87">reply</a> </span> </div> <div class="text"><p>application.ini:<br /> resources.db.adapter = &ldquo;pdo_mysql&rdquo;<br /> resources.db.params.host = &ldquo;localhost&rdquo;<br /> resources.db.params.username = &ldquo;xxx&rdquo;<br /> resources.db.params.password = &ldquo;xxx&rdquo;<br /> resources.db.params.dbname = &ldquo;xxx&rdquo;</p> <p>bootstrap.php:<br /> $this-[HTML_REMOVED]bootstrap(&lsquo;db&rsquo;);<br /> $entityManager = \Doctrine\ORM\EntityManager::create(array(<br /> &lsquo;pdo&rsquo; =[HTML_REMOVED] $this-[HTML_REMOVED]getResource(&lsquo;db&rsquo;)-[HTML_REMOVED]getConnection()<br /> ), $config);</p> <p>Now I can still use Zend_Auth_Adapter_DbTable.</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Deon Slabbert</span> <span class="date">Jan. 21, 2012, 11:53 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-88">reply</a> </span> </div> <div class="text"><p>Worked first time! Thanks a lot for this tutorial. I have been struggeling with this integration issue for quite some time. Until now that is :-)</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Mark Hofstetter</span> <span class="date">Jan. 26, 2012, 3:14 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-89">reply</a> </span> </div> <div class="text"><p>thank you very much for this concise tutorial. If you have installed doctrine via pear there is no need to define a path for the ClassLoader</p> <p>public function _initDoctrine() {<br /> // include and register Doctrine&rsquo;s class loader<br /> require_once(&lsquo;Doctrine/Common/ClassLoader.php&rsquo;);<br /> $classLoader = new \Doctrine\Common\ClassLoader(<br /> &lsquo;Doctrine&rsquo;<br /> ## , APPLICATION_PATH . &lsquo;/../library/&rsquo;<br /> ## doctrine is installed via pear!</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Ganga Bohara</span> <span class="date">Jan. 26, 2012, 3:41 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-90">reply</a> </span> </div> <div class="text"><p>Hi My Name is Ganga Bohara and I am new to zend and Doctrine. Thanks to your tutorial that I could integrate Doctrine with Zend. But I am having problem with Many to many relationship. When I run the command &ldquo;./doctrine orm:schema-tool:create&rdquo; from the bin directory, it throws the following waring and the tables do not get created.</p> <p>Creating database schema&hellip;<br /> PHP Warning: class_parents(): Class Roles does not exist and could not be loaded in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222</p> <p>Warning: class_parents(): Class Roles does not exist and could not be loaded in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222<br /> PHP Warning: array_reverse() expects parameter 1 to be array, boolean given in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222</p> <p>Warning: array_reverse() expects parameter 1 to be array, boolean given in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222<br /> PHP Warning: Invalid argument supplied for foreach() in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222</p> <p>Warning: Invalid argument supplied for foreach() in /var/www/sai-library/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222</p> <p>Could anybody help me why its not finding the class. I have put all the entity classes inside the models folder</p></div> </li> <li class="comment"> <div class="head"> <span class="author">agung susanto</span> <span class="date">March 17, 2012, 11:31 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-91">reply</a> </span> </div> <div class="text"><p>thanks for great tutorial,</p> <p>i have run once and insert twice in mysql database?</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">agung susanto</span> <span class="date">March 17, 2012, 11:36 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-92">reply</a> </span> </div> <div class="text"><p>sori i have Resolved it, <br /> i used firephp active on chrome when i set firephp off it insert single row data</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">shah</span> <span class="date">April 18, 2012, 12:50 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-93">reply</a> </span> </div> <div class="text"><p>In model we make Entity Class.</p> <p>$testEntity = new Default_Model_Test();<br /> $result = $_em-[HTML_REMOVED]getRepository($testEntity)-[HTML_REMOVED]findOneByName(&#145;abc&#146;);</p> <p>this code write in Controller action.</p> <p>is it possible to pick data(write DQL) from model?why pick from controller..</p> <p>thanks</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">April 18, 2012, 3:37 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-94">reply</a> </span> </div> <div class="text"><p>I&rsquo;m sorry, I don&rsquo;t understand your question.</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">shah</span> <span class="date">April 18, 2012, 4:49 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-95">reply</a> </span> </div> <div class="text"><p>Actually am a newbe in Zend and also Doctrine.am tryting a sample crud operation in my sample project.am not getting any sample example.I just want to simple list,add,edit,delete operation.</p> <p>public function indexAction()<br /> {<br /> //Pick data from Database using Doctrine and show view<br /> }</p> <p>public function addAction()<br /> {<br /> //Pick User input from view and add Database using Doctrine <br /> }<br /> public function editAction()<br /> {<br /> //Pick User information from database display view.User edit information and save it to Database using Doctrine <br /> }</p> <p>public function deleteAction()<br /> {<br /> //Delete data from database using Doctrine. <br /> }</p> <p>could u please put sample code in this function..</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Arthur</span> <span class="date">June 17, 2012, 1:11 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-96">reply</a> </span> </div> <div class="text"><p>Hi, </p> <p>Great tutorial but does not work.</p> <p>When i get any user from entityManager<br /> ..<br /> $registry = Zend_Registry::getInstance();<br /> $this-[HTML_REMOVED]_em = $registry-[HTML_REMOVED]entitymanager;</p> <p>$user = $this-[HTML_REMOVED]_em-[HTML_REMOVED]find(&lsquo;Usuario&rsquo;)-[HTML_REMOVED]findOneBy(array(<br /> &lsquo;usuario&rsquo; =[HTML_REMOVED] $this-[HTML_REMOVED]username,<br /> &lsquo;senha&rsquo; =[HTML_REMOVED] $this-[HTML_REMOVED]password<br /> ));<br /> ..</p> <p>i receive this error:</p> <p>Exception information: Message: Class Usuario does not exist<br /> I spent hours researching and i can not find a solution.</p> <p>thanks</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Zend Framework and Doctrine 2 integration. &amp;laquo; Codeperl&amp;#039;s Knowledge Sharing System</span> <span class="date">July 1, 2012, 3:58 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-97">reply</a> </span> </div> <div class="text"><p>[&hellip;] http://www.oelerich.org/integrate-doctrine-2-with-zend-framework-1-11-3/ [&hellip;]</p></div> </li> <li class="comment"> <div class="head"> <span class="author">G</span> <span class="date">July 26, 2012, 4 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-99">reply</a> </span> </div> <div class="text"><p>Hey Oli,<br /> It seems that I&rsquo;m the only one to have this problem: I can do your tuto until the creation of the table, but my website doesn&rsquo;t work anymore (HTTP error 500) so I&rsquo;m blocked. I can&rsquo;t go further.</p> <p>I identified the problem in the line <code>$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);</code> of the bootstrap. Strange isn&rsquo;t it?</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">July 26, 2012, 4:03 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-100">reply</a> </span> </div> <div class="text"><p>Hi G, it looks like the connection is wrong. Try putting the app in development mode by setting APPLICATION_ENV=development. Then, errors should be displayed. Also, you can have a look into the server&rsquo;s error log files. There, the error messages are logged as well.</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Charlie</span> <span class="date">July 30, 2012, 6:05 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-101">reply</a> </span> </div> <div class="text"><p>An awesome tutorial. like some of people here, I am just beginning to use ZF and Doctrine as well. I spent several hours trying to understand the documentation of Dotrine but couldn&rsquo;t get anywhere with that. </p> <p>This tutorial was exactly what I needed! Really appreciate it and hope to see another tutorial with ZF 2. Thanks</p> <p>Charlie</p></div> </li> <li class="comment"> <div class="head"> <span class="author">prasad</span> <span class="date">Aug. 17, 2012, 8:15 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-103">reply</a> </span> </div> <div class="text"><p>thanks for the info. it is very useful for me to understand easily about doctrine&hellip;&hellip;</p></div> </li> <li class="comment"> <div class="head"> <span class="author">stackongunsafe</span> <span class="date">Sept. 14, 2012, 9:25 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-107">reply</a> </span> </div> <div class="text"><p>Thank you for good tutorial</p></div> </li> <li class="comment"> <div class="head"> <span class="author">vagex</span> <span class="date">Sept. 30, 2012, 9:16 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-108">reply</a> </span> </div> <div class="text"><p>I know this if off topic but I&rsquo;m looking into starting my own weblog and was curious what all is required to get set up? I&rsquo;m assuming <br /> having a blog like yours would cost a pretty penny?<br /> I&rsquo;m not very web smart so I&rsquo;m not 100% sure. Any suggestions or advice would be greatly appreciated. Thank you</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Sept. 30, 2012, 11:45 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-109">reply</a> </span> </div> <div class="text"><p>Hi vagex, you can get a free wordpress blog (like mine) on http://wordpress.com/. <br /> Only if you want a nice domain, you would have to pay.</p> <p>Regards, Oli</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">Darcy</span> <span class="date">Oct. 20, 2012, 9:30 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-110">reply</a> </span> </div> <div class="text"><p>With havin so much written content do you ever run into any problems of plagorism <br /> or copyright infringement? My blog has a lot of completely unique content I&rsquo;ve either authored myself or outsourced but it looks like a lot of it is popping it up all over the web without my permission. Do you know any techniques to help stop content from being ripped off? I&rsquo;d truly appreciate <br /> it.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">Oct. 20, 2012, 10:51 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-111">reply</a> </span> </div> <div class="text"><p>I am happy when people take my code/content and reuse it. That is why I open source or publish it.</p></div> </li> </ul> <li class="comment"> <div class="head"> <span class="author">ram yadav</span> <span class="date">Jan. 17, 2013, 10:08 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-113">reply</a> </span> </div> <div class="text"><p>Hi<br /> Form where i found doctrine complete package, the url you provide is go to not found page. </p> <p>currently i found from git-hub https://github.com/doctrine/doctrine2/tree/2.3</p> <p>but this is not working having Doctrine/Common/ClassLoader.php file missing</p> <p>and your download Url http://www.doctrine-project.org/projects/orm/download is go to not found page.</p> <p>please provide me correct download link if you know.</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Jesus</span> <span class="date">Sept. 7, 2013, 1:10 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-196">reply</a> </span> </div> <div class="text"><p>How i use ArrayCollection() </p> <p>in the model onetomany????</p></div> </li> <li class="comment"> <div class="head"> <span class="author">Sunny Patial</span> <span class="date">July 15, 2014, 6:03 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-232">reply</a> </span> </div> <div class="text"><p>Great tutorials!!!<br /> But i have a query..<br /> I don&#8217;t want to use model class name like &#8220;Default_Model_Test&#8221;.<br /> i want to use like &#8220;test&#8221; because test is my table name.<br /> So what i would be change in the bootstrap.php or application.ini settings.<br /> So that i can call it in controller with test() class</p> <p>Thanks..</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">July 15, 2014, 9:06 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-233">reply</a> </span> </div> <div class="text"><p>Just rename your entity. As far as I remember there is no required naming scheme. </p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Sunny Patial</span> <span class="date">July 16, 2014, 3:02 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-234">reply</a> </span> </div> <div class="text"><p>First of all thanks for reply.</p> <p>But i have got same issue &#8220;Fatal error: Class &#8216;Entities\test not found &#8220;.<br /> Please suggest me so that i can resolve it.</p> <p>I am not using following code in bootstrap.php file, because i don&#8217;t want to use Default_Model_Test. i want to use Test only.</p> <p>/*<em><br /> * Register namespace Default_<br /> * @return Zend_Application_Module_Autoloader<br /> </em>/<br /> protected function <em>initAutoload()<br /> {<br /> $autoloader = new Zend_Application_Module_Autoloader(array(<br /> &#8216;namespace&#8217; =&gt; &#8216;Default</em>&#8216;,<br /> &#8216;basePath&#8217; =&gt; dirname(<strong>FILE</strong>),<br /> ));<br /> return $autoloader;<br /> }</p> <p>Following is the my entity file which is present in model/Entities/test.php</p> <p>[HTML_REMOVED]</p> <p>use Doctrine\ORM\Mapping AS ORM;<br /> /<strong><br /> * @ORM\Entity<br /> */<br /> class Test<br /> {<br /> /</strong><br /> * @ORM\Id<br /> * @ORM\Column(type=&#8221;integer&#8221;, length=11)<br /> * @ORM\GeneratedValue(strategy=&#8221;AUTO&#8221;)<br /> */<br /> private $id;</p> <p>/*<em><br /> * @ORM\Column(type=&#8221;string&#8221;, length=255, nullable=true)<br /> </em>/<br /> private $name; <br /> }</p> <p>and i am calling in controller with following code, but its not working give me an error.</p> <p>$testEntity = new Entities\Test();<br /> $testEntity-&gt;setName(&#8216;Zaphod Beeblebrox&#8217;);<br /> $this-&gt;_em-&gt;persist($testEntity);<br /> $this-&gt;_em-&gt;flush();</p> <p>Please suggest me.<br /> Thanks.</p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Oli</span> <span class="date">July 16, 2014, 4:11 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-235">reply</a> </span> </div> <div class="text"><p>Oh, I forgot about the zend autoloader. In that case, I don&#8217;t know how to achieve other naming conventions. I didn&#8217;t work with the framework for years. You should read the docs on the autoloader to find out more. </p></div> </li> <ul> <li class="comment"> <div class="head"> <span class="author">Sunny Patial</span> <span class="date">July 17, 2014, 6:34 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-236">reply</a> </span> </div> <div class="text"><p>ok fine, thanks for reply.</p></div> </li> </ul> </ul> </ul> </ul> <li class="comment"> <div class="head"> <span class="author">Carlos Shirasawa</span> <span class="date">April 15, 2015, 4:53 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-242">reply</a> </span> </div> <div class="text">&lt;p&gt;Great tutorial Oli, saved several work hours for me.&lt;/p&gt; &lt;p&gt;Thanks!&lt;/p&gt;</div> </li> </ul></section>

Write comment