Topic: Bootstrapping Doctrine in Zend 1.8 or 1.9
I've been using Doctrine a lot as an alternative to Zend_Db with great success. here's my bootstrap method (sits in the Bootstrap.php file) in case anyone is interested:
protected function _initDoctrine()
{
$this->bootstrap("autoload");
$dbConfig = $this->options['db'];
defined('CONFIG_PATH') || define('CONFIG_PATH', APPLICATION_PATH . '/configs');
defined('DATA_FIXTURES_PATH') || define('DATA_FIXTURES_PATH', CONFIG_PATH . '/data/fixtures');
defined('SQL_PATH') || define('SQL_PATH', CONFIG_PATH . '/data/sql');
defined('MIGRATIONS_PATH') || define('MIGRATIONS_PATH', CONFIG_PATH . '/migrations');
defined('YAML_SCHEMA_PATH') || define('YAML_SCHEMA_PATH', CONFIG_PATH . '/schema.yml');
defined('MODELS_PATH') || define('MODELS_PATH', APPLICATION_PATH . '/models');
defined('DB_PATH') || define('DB_PATH' , 'mysql://' . $dbConfig['username']. ':' . $dbConfig['password']. '@' . $dbConfig['host']. '/' . $dbConfig['name']);
require_once 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
$connection = Doctrine_Manager::connection(DB_PATH);
$connection->setCharset('UTF8');
Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative');
Doctrine::loadModels(MODELS_PATH);
}
this code assumes that the database configurin is sitting in your application.ini file. Also, Doctrine is sitting in /library/Doctrine. Thanks to Maxime Bouroumeau, I've also got a modified version of the Doctrine.php command line script:
<?php
error_reporting(E_ALL);
define('ROOT_PATH', dirname(dirname(dirname(__FILE__))));
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));
define('APPLICATION_ENV', 'development');
define('TMP_PATH', realpath(dirname(__FILE__) . '/../tmp/'));
//Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->getBootstrap()->bootstrap("doctrine");
// Configure Doctrine Cli
// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled
$config = array('data_fixtures_path' => DATA_FIXTURES_PATH,
'models_path' => MODELS_PATH,
'migrations_path' => MIGRATIONS_PATH,
'sql_path' => SQL_PATH,
'yaml_schema_path' => YAML_SCHEMA_PATH);
$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);
Hope this helps other integrators!