【发布时间】:2009-12-10 05:02:59
【问题描述】:
我正在学习Introducing Doctrine 1.2 Integration的教程
我有一个“引导程序”的教义.php?教义...抱歉,我还没有完全理解本教程。
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));
// 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']);
当我尝试通过 cmd 运行它时,
php.exe doctrine.php
我明白了
D:\Projects\ZF\doctrine\application\scripts>php -f doctrine.php
PHP Fatal error: Uncaught exception 'LogicException' with message 'Passed array does not specify an existing static met
hod (class 'Doctrine' not found)' in D:\Projects\ZF\doctrine\application\Bootstrap.php:7
Stack trace:
#0 D:\Projects\ZF\doctrine\application\Bootstrap.php(7): spl_autoload_register(Array)
#1 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(662): Bootstrap-
>_initDoctrine()
#2 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(622): Zend_Appli
cation_Bootstrap_BootstrapAbstract->_executeResource('doctrine')
#3 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\BootstrapAbstract.php(579): Zend_Appli
cation_Bootstrap_BootstrapAbstract->_bootstrap('doctrine')
#4 D:\Projects\ZF\doctrine\application\scripts\doctrine.php(25): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap
('doctrine')
#5 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Loader.php(136): include('D:\Projects\ZF in D:\Projects\ZF\d
octrine\application\Bootstrap.php on line 0
更新 1
protected function _initDoctrine() {
$this->getApplication()->getAutoloader()
->pushAutoloader(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$doctrineConfig = $this->getOption("doctrine");
$conn = Doctrine_Manager::connection($doctrineConfig['dsn']);
$conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
return $conn;
}
在sql\_autoload\_register() 下我猜。我真的不明白spl\_autoload\_register() 的意思......即使在 php 参考中也是如此。
更新 2
我的 bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initDoctrine() {
$this->getApplication()->getAutoloader()
->pushAutoloader(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$doctrineConfig = $this->getOption("doctrine");
Doctrine::loadModels($doctrineConfig['models_path']);
$conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'Doctrine');
$conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
return $conn;
}
}
我猜这不起作用是 Zend 似乎没有自动加载 Doctrine 类。它应该是因为我已经在 config.ini 中注册了 Doctrine 命名空间
autoloaderNamespaces[] = "Doctrine"
这是否意味着 Zend shld 自动加载 Doctrine 类?
至于 Doctrine 的存储位置,我已经在 PHP 的包含路径中指出了它。
include_path = ".;c:\php\includes;D:\ResourceLibrary\Frameworks\ZendFramework\library;D:\ResourceLibrary\Frameworks\Doctrine121sandbox\lib"
我注意到,如果在_initDoctrine() 中,我需要手动操作 Doctrine。
require_once 'D:\ResourceLibrary\Frameworks\Doctrine121sandbox\lib\Doctrine.php';
是否与 windows 路径有关(\ 作为分隔符)
【问题讨论】:
-
你解决过这个问题吗?
-
实际上并非如此,我想临时解决方法是将教义库放在项目库文件夹中。似乎将教义放在一个文件夹中并将该文件夹包含在 php.ini 中对我不起作用。我正在使用 Windows 7,wamp 2
-
如果您想立即启动并运行,请尝试使用github.com/beberlei/zf-doctrine。迄今为止我遇到的最简单、最完整(尽管并非没有错误)的 zend/doctrine 集成解决方案。
标签: php zend-framework doctrine