0
什麼是build.php-> generateModelsFromYaml(..)中的schema.yml的好路徑?generateModelsFromYaml的路徑問題(..)
項目的路徑:
/config
-global.php
/lib
/model
/config
-schema.yml
/vendor
/doctrine
...
/web
-index.php
-build.php
/config/global.php:
<?php
////////////////////////////////////////////////////////
///////////////////// paths ////////////////////////////
////////////////////////////////////////////////////////
define('LIB_DIR', dirname(__FILE__).'/../lib/');
define('CFG_DIR', dirname(__FILE__).'/');
define('WEB_DIR', dirname(__FILE__).'/../web/');
////////////////////////////////////////////////////////
//////////////////// doctrine conf /////////////////////
////////////////////////////////////////////////////////
define('CFG_DB_DSN', 'mysql://[email protected]/parcvehicule');
require_once(LIB_DIR.'vendor/doctrine/Doctrine.php');
spl_autoload_register(array('Doctrine_Core', 'autoload'));
spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$conn = Doctrine_Manager::connection(CFG_DB_DSN, 'doctrine');
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
Doctrine_Core::loadModels(LIB_DIR.'model/');
?>
/build.php:
<?php
require_once('config/global.php');
echo $_SERVER["PHP_SELF"];
// Si elle existe, supprimez la base existante.
// Attention, cela vide totalement la base de données !
Doctrine_Core::dropDatabases();
// Création de la base (uniquement si elle n'EXISTE PAS)
Doctrine_Core::createDatabases();
// Création des fichiers de modèle à partir du schema.yml
// Si vous n'utilisez pas le Yaml, n'exécutez pas cette ligne !
Doctrine_Core::generateModelsFromYaml('/lib/model/config/schema.yml', '/lib/model/',
array('generateTableClasses' => true));
// Création des tables
Doctrine_Core::createTablesFromModels('/lib/model');
?>
和輸出build.php的:
/parcVehicule/build.php
Fatal error: Uncaught exception 'Doctrine_Import_Exception' with message
'No yml schema found in /lib/model/config/schema.yml'
in C:\Program Files (x86)\wamp\www\parcVehicule\lib\vendor\doctrine\Doctrine\Import\Schema.php:277
Stack trace: #0 C:\Program Files (x86)\wamp\www\parcVehicule\lib\vendor\doctrine\Doctrine\Core.php(883):
Doctrine_Import_Schema->importSchema('/lib/model/conf...', 'yml', '/lib/model/')
#1 C:\Program Files (x86)\wamp\www\parcVehicule\build.php(16):
Doctrine_Core::generateModelsFromYaml('/lib/model/conf...', '/lib/model/', Array)
#2 {main} thrown in C:\Program Files (x86)\wamp\www\parcVehicule\lib\vendor\doctrine\Doctrine\Import\Schema.php on line 277
感謝您的幫助,但它不工作...同樣的錯誤。可能是PHP的配置?我正在使用wamp工作Win7 – canardman 2011-03-03 08:55:12
不,我不認爲它是一個PHP配置。嘗試查看generateModelsFromYaml方法並調試該方法如何嘗試打開文件夾。這可能會有所幫助。 – maectpo 2011-03-03 11:12:18
無論如何,這個配置適用於Windows(Denwer)和Linux(LAMP) – maectpo 2011-03-03 19:21:34