Question

I'm new to doctrine. I created an bootstrap file like the following one:

require_once(dirname(__FILE__)."/../conf/general.php");
require_once(dirname(__FILE__).'/Doctrine/lib/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));

$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL); 
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); #for accessor  overriding
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true); #in order to be able to use the XTable classes
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING,    Doctrine_Core::MODEL_LOADING_CONSERVATIVE); #to conservatively load files
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL); 

$dsn = "mysql:dbname=".DBNAME.";host=".DBHOST;
$dbh = new PDO( $dsn, DBUSERNAME, DBPASS );
$conn = Doctrine_Manager::connection( $dbh ); 
Doctrine_Core::loadModels('doc_models'); #In order to be able to work with models

php bootstrap.php
command works just as expected. But I have a file X.php under directory Y and i require bootstrap.php file in X.php ;but when i ran the X.php in the directory Y like
 php X.php
I got the following exception:

Doctrine_Exception: You must pass a valid path to a directory containing Doctrine models in /path_to_directory_of_bootstrap_file/Doctrine/lib/Doctrine/Core.php on line 635

Now, how can i fix this issue?

BTW, when i put X.php and bootstrap.php in the same directory it works as expected. I also tried to require with absolute paths but this didn't solve my problem. I'm testing on Ubuntu 9.10 and installed doctrine from pear. Doctrine version is 1.2.0.

Was it helpful?

Solution

Did you try using absolute paths while requiring? Realpath can help you create those paths.

OTHER TIPS

I think this error gets triggered when doctrine is expecting some model directories to exist. The error also occurs if you try to generate SQL from a schema.yml BEFORE you have built the model classes. When the model classes get built they create a bunch of directories and it's these that i think you are missing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top