我正在使用Zend Framework 2.0在我的应用程序中自动加载Zend类,而不依赖于MVC框架。
zend框架的位置是C:/ wamp / library / zendframework / library(包含Zend / Soap等)。
以下是我的代码:
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array(
'Zend' => 'c:/wamp/library/zendframework/library'));
$loader = new Zend\Loader\StandardAutoloader();
$loader->registerNamespace('Zend', 'c:/wamp/library/zendframework/library');
$loader->register();
$auto = new Zend/Soap/Server(null,null);
$auto->setClass('services');
$auto->handle();
我正在尝试加载Zend / Soap / Server,但我一直收到错误:
Fatal error: Class 'Zend' not found in C:\wamp\www\Zend_soap\server.php on line 42
在第42行:
$auto = new Zend/Soap/Server(null,null);
答案 0 :(得分:0)
非常接近,我认为;
如果您的ZF2安装在php include_path上,那么您应该只需要3行代码,如果是,则需要4行;不在include_path上。
require_once 'Zend/Loader/StandardAutoloader.php';
//if ZF2 is on php include_path set autoregister_zf to true else false
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
//Zend would be a vendor prefix not namespace, however a namespace may work just fine
//$loader->registerNamespace('Zend', 'c:/wamp/library/zendframework/library');
//if ZF2 is not on php include path and needs to be registered as a vendor
//$loader->registerPrefix('Zend', 'c:/wamp/library/zendframework/library');
$loader->register();
祝你好运!我希望这会有所帮助。autoregister_zf :一个布尔值,表示该类应该 将“Zend”命名空间注册到上面的目录中 classfile位于文件系统上。