views:

43

answers:

1

i use zend framework 1.10 and i have a script under scripts library.

i run this script from command line.

how can i load all the models of doctrine and use them in my script.

in the begining of the script i write

/**
 * Doctrine CLI script
 */
define('APPLICATION_ENV', 'production');
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH . '/../library/lib'),
    realpath(APPLICATION_PATH . '/models/generated'),
    realpath(APPLICATION_PATH .'/models'),
    get_include_path()
))); 

require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);

then i connect to doctrine

require_once 'Doctrine.php';

$doctrineConfig = $application->getOption('doctrine');
$manager = Doctrine_Manager::getInstance();
$manager->openConnection($doctrineConfig['connection_string']);

then when i try to run a query like :

 $q = Doctrine_Query::create()
            ->select('c.CampaignId')            
            ->from('ModelCampaigns c');

he write an error :

Fatal error: Uncaught exception 'Doctrine_Exception' with message 'Couldn't find class ModelCampaigns'

A: 

its ok now i add this to script :

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);

$moduleLoader = new Zend_Application_Module_Autoloader(array(
    'namespace' => '',
    'basePath' => APPLICATION_PATH));
Haim Evgi