Problems integrating Zend Framework and Doctrine
I've done this before on another machine and the setup is almost identical. However, its just not working on the new machine. When I try and get Doctrine to generate my models, its putting them in the wrong place. Its creating an extra "Model" directory both for the base classes as well as the regular classes. I'm using Doctrine 1.2.3 with ZF 1.11.0. Here is my ZF application.ini:
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "America/Denver"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
autoloaderNamespaces[] = "Doctrine_"
autoloaderNamespaces[] = "App_"
doctrine.connection_string = "mysql://root@localhost/mydb"
;doctrine.cache = true
doctrine.data_fixtures_path = 开发者_运维知识库APPLICATION_PATH "/doctrine/data/fixtures"
doctrine.sql_path = APPLICATION_PATH "/doctrine/data/sql"
doctrine.migrations_path = APPLICATION_PATH "/doctrine/migrations"
doctrine.yaml_schema_path = APPLICATION_PATH "/doctrine/schema"
doctrine.models_path = APPLICATION_PATH "/models"
doctrine.generate_models_options.pearStyle = true
doctrine.generate_models_options.generateTableClasses = true
doctrine.generate_models_options.generateBaseClasses = true
doctrine.generate_models_options.baseClassPrefix = "Base_"
doctrine.generate_models_options.baseClassesDirectory =
doctrine.generate_models_options.classPrefixFiles = false
doctrine.generate_models_options.classPrefix = "Model_"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Here is my Doctrine function from my ZF Bootstrap.php file:
protected function _initDoctrine()
{
$this->getApplication()->
getAutoloader()->
pushAutoloader(array('Doctrine_Core', 'autoload'));
$config = $this->getOption('doctrine');
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'Model_');
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_PEAR);
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
if (isset($config['cache']) && $config['cache'] == true) {
$cacheDriver = new Doctrine_Cache_Apc();
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
}
$connection = $manager->openConnection($config['connection_string'], 'doctrine');
$connection->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
$connection->setCharset('utf8');
return $connection;
}
And here is my doctrine.php command line script:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// 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');
$config = $application->getOption('doctrine');
$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);
So, I'm expecting my models directory to end up like this:
models
Base
-Class1.php
-Class2.php
-Class1.php
-Class1Table.php
-Class2.php
-Class2Table.php
where the base class class names are formatted like Model_Base_Class1 and the regular class names are Model_Class1 (in the actual php files themselves). Instead, what I'm getting is:
models
Base
Model
-Class1.php
-Class2.php Model
-Class1.php
-Class1Table.php
See the extra Model directories? What is causing this? I've tried messing with the doctrine.generate_models_options.classPrefix option in my ini as well as the similar setting in my Bootstrap.php file - $manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'Model_');
Please help me!
Well, I'm not so smart once again. :( All it was, was a misconfiguration of my schema.yaml file. I had put Model_User as the model name instead of just User! The fixtures file does require it to be Model_User though. Problem solved.
精彩评论