2011-08-11 46 views
3

我從來沒有真正玩過類,但我正在尋找使用php-ews在我正在atm工作的頁面上。加載類時發生致命錯誤EWSType_FindItemType(php-ews)

我的主要文件是通過調用5「根」 PHP文件包括

include ("php-ews/ExchangeWebServices.php"); 
include ("php-ews/EWS_Exception.php"); 
include ("php-ews/EWSType.php"); 
include ("php-ews/NTLMSoapClient.php"); 
include ("php-ews/NTLMStream.php"); 

但這些抱怨中有子文件夾的文件不包括在內,在這種情況下。

Fatal error: Class 'EWSType_FindItemType' not found in C:\wamp\www\intranet\dashboard\mailtest.php on line 19 

我已經嘗試在EWSType.php文件中包含上述文件,然後它抱怨未包括下一個文件。我已經嘗試過在文件夾中包含任何.php文件的方法,但這不起作用。

我假設我只是想要加載一個類錯誤,並想知道是否有人可以告訴我的方式!

回答

1

而不是手動加載類,嘗試__autoload他們。這樣你就不必擔心保持包含列表。自動加載器會爲你做。 應該很容易,如果類文件調用與類本身相同。

http://php.net/manual/en/function.spl-autoload-register.phphttp://de3.php.net/manual/en/language.oop5.autoload.php的細節

function ews_autoloader($className) { 
    if($className != 'EWS_Exception') { 
    $classPath = str_replace('_','/',$className); 
    } 
    if(file_exists("php-ews/{$classPath}.php") { 
    include("php-ews/{$classPath}.php"); 
    } 
} 

spl_autoload_register('ews_autoloader'); 
+0

不幸的是,文件沒有該功能適當命名,倉庫就設在這裏的文件名http://code.google.com/p/php-ews/source/browse/ – Xand94

+0

@ Xand94:所以我改進了一點;) – Mchl

+1

呃...它仍然需要一個更改來處理EWS_Exception ... – Mchl

0

管理放在一起的代碼一點點地得到包括主文件夾的文件。

$dir = '/wamp/www/intranet/dashboard/php-ews/EWSType/'; 
$files1 = scandir($dir); 
foreach ($files1 as $value) { 
if(preg_match('/\.php$/i', $value)){ 
$inc = "php-ews/EWSType/"; 
$inc .= $value; 
include ($inc); 
}} 
相關問題