我正在关注Introducing Doctrine 1.2 Integration
中的教程我有一个doctrine.php“bootstraps?”学说...对不起我还没有完全理解这个教程。
// 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()
下我猜。即使在php参考中,我也没有真正得到spl\_autoload\_register()
...
更新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 autoload Doctrine类?
至于Doctrine的存储位置,我在PHP的include路径中指出了它。
include_path = “C:\ PHP中\包括; d:\ ResourceLibrary \框架\ ZendFramework \文库; d:\ ResourceLibrary \框架\ Doctrine121sandbox \ lib中”
我注意到,如果在_initDoctrine()
中,我需要手动操作Doctrine。
require_once 'D:\ResourceLibrary\Frameworks\Doctrine121sandbox\lib\Doctrine.php';
它与Windows路径(\作为分隔符)
有关答案 0 :(得分:0)
你是否有其余的Zend Framework工作没有使用Doctrine?如果是这样,您有一个用于该应用程序的引导程序文件。假设一个默认的目录布局,如果你的脚本目录中有doctrine.php,而你的应用程序目录中有你的bootstrap.php,那么你应该可以这样做,让你的doctrine cli在doctrine.php中工作:
require dirname(__FILE__).'/../application/global.php';
// the config line below might be different based on how you have your
// doctrine config stuff set up
$cli = new Doctrine_Cli(Zend_Registry::get('doctrine_config'));
$cli->run($_SERVER['argv']);
在bootstrap.php(或bootstrap.php所需的文件)中,您的自动加载器应配置如下:
// set up your include path here
set_include_path(dirname(__FILE__).'/../library/zendframework'
. PATH_SEPARATOR . dirname(__FILE__).'/../library/doctrine'
. PATH_SEPARATOR . dirname(__FILE__).'/models'
. PATH_SEPARATOR . dirname(__FILE__).'/models/generated'
. PATH_SEPARATOR . dirname(__FILE__).'/business'
. PATH_SEPARATOR . dirname(__FILE__).'/business/exceptions'
. PATH_SEPARATOR . dirname(__FILE__).'/business/util'
. PATH_SEPARATOR . dirname(__FILE__).'/business/validators'
. PATH_SEPARATOR . get_include_path());
require 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->suppressNotFoundWarnings(false);
$loader->setFallbackAutoloader(true);
如果这不起作用,请在此处发布。我们在一开始就使用Zend Framework的自动加载器设置了一些问题。
答案 1 :(得分:0)
我确实面临同样的问题并成功克服了它 你需要做的是改变这个
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
到
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, false);
我确实删除了这一行
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
我在同一zendcasts forums中报告了这些错误 这些步骤帮助我按照预期处理学说:)