2012-10-09 44 views
0

我使用Zend Framework 2.0来自动加载我的应用程序中的Zend类,独立于MVC框架。Zend自动加载器不加载Zend类

Zend Framework的位置,是C:/ WAMP /库/ zendframework /库(包含的Zend /肥皂等)

下面是我的代码:

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 /香皂/服务器,但我不断收到错误:

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

非常接近,我想;
如果您的ZF2安装位于php include_path上,那么您应该只需要3行代码,如果它不在include_path上,则只需要4行代码。

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: An boolean value indicating that the class should register the “Zend” namespace to the directory above where its own classfile is located on the filesystem.

祝您好运!我希望这有助于。