tags:

views:

724

answers:

1

Hello all,

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.

+1  A: 

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

chelmertz
I tried absolute paths and got no use.Sorry I forgot to mention in my post, i'll update the post. BTW when i change my directory with chdir to the directory of bootstrap.php, it seems to work. But it looks awkward to me to use chdir and change the path of file in every file which is requiring the bootstrap.php . I think, there must be better solution for this.
systemsfault