In my previous post I described how to set up Zend Framework project to work with Doctrine 2 ORM. Here is a quick note on how to make Doctrine 2 Console work in this environment.
First of all I had to mention that I did not install Doctrine using PEAR. If you did so command line tool should be already available to you and the process of configuration is slightly different from what I will show you above (links will be given at the end of the post).
So in my Zend Framework project I had a scripts folder. There I created two files: “doctrine” and “doctrine.php”. First is the shell script. I just copied it from bin folder of Doctrine download and changed the path to php binary in the first line. I am using MacOS with XAMPP (on Windows you should use doctrine.bat).
You should make this script executable in order to run it from terminal.
Second file in our scripts folder is “doctrine.php”. Let’s take a look at it.
Few moments here. This script uses bootstrap method from the previous post to set up Doctrine class loaders and entity manager. We don’t need here anything more and Zend_Application allows us to do just what we want.
All the commands of the Doctrine Console require either the db or the em helpers to be defined in order to work correctly. Doctrine Console requires the definition of a HelperSet that is the DI (Dependency Injection) tool to be injected in the Console. So there is no problem since we’ve got em from the bootstrap.
So everything is set up. Just type ./doctrine.php in your terminal and you’ll see list of commands provided by Doctrine Console.
And, finally, one example. If you want to create tables in you database from annotations definition of your entities just run the following command:./doctrine orm:schema-tool:update —force
Or if you just want to get SQL:
./doctrine orm:schema-tool:update —dump-sql
You can find some more info on setting up and using Doctrine Console in the documentation or going through links from previous post.
Good luck!
