2012-10-09 45 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.

祝您好運!我希望這有助於。