In this first of a serious of articles where we delve into some of the hidden treasures in our ViMbAdmin application, we look at how to integrate Doctrine ORM with Zend – and specifically Zend_Application and Zend_Controller.
The first assumption (and requirement) we are going to make is that you are using Zend_Application. If you want to see a working application set up and configured for this, please checkout or browse our ViMbAdmin source code – which we’ll reference throughout this document.
Zend Application has a resource framework which allows us to bootstrap various resources on demand. We have created a Doctrine resource for this very purpose which you can download from here (and you may need to edit the class name and change the plugin path in the config code below to match your setup). Our implementation does many things:
- instantiates the Doctrine object;
- sets up an autoloader for Doctrine models;
- instantiates the Doctrine manager;
- opens the connection to the database;
- sets all collations and character sets to UTF8 (this is hard coded but can easily be changed);
- sets various hard coded Doctrine attributes which can also be changed.
We the add various configuration parameters to the
pluginPaths.ViMbAdmin_Resource = APPLICATION_PATH "/../library/ViMbAdmin/Resource" resources.doctrine.connection_string = "phptype://username:password@host/database" resources.doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures" resources.doctrine.models_path = APPLICATION_PATH "/models" resources.doctrine.migrations_path = APPLICATION_PATH "/../doctrine/migrations" resources.doctrine.sql_path = APPLICATION_PATH "/../doctrine/data/sql" resources.doctrine.yaml_schema_path = APPLICATION_PATH "/../doctrine/schema" resources.doctrine.generate_models_options.generateTableClasses = true resources.doctrine.extensions_path = APPLICATION_PATH "/../library/DoctrineExtensions"
Or the following where $application is the instance of Zend_Application:
$application->getBootstrap()->bootstrap( 'doctrine' );
From that, you can use Doctrine to your hearts content!
We also have a Doctrine CLI script which works from the same resource. See: