2013-08-05 28 views
0

我嘗試註冊了幾個自動加載機和我得到一個HTTP 500錯誤我說日誌以下:我的自動加載器有什麼問題?

[05-Aug-2013 04:32:38 UTC] PHP Fatal error: Uncaught exception 'LogicException' with message 'Function 'Autoloader::config' not callable (non-static method Autoloader::config() should not be called statically)' in /home2/canforce/public_html/index.php:5

有上的錯誤日誌的結尾部分堆棧跟蹤的一部分,但它來顯示大寫字母,所以我把它拿出來,我不認爲這很重要。

我想我應該自動加載磁帶機根據我讀過什麼工作,但由於某種原因,這不,下面的代碼:


的index.php

include("config/autoloader.php"); 
spl_autoload_register('Autoloader::config'); 
spl_autoload_register('Autoloader::controller'); 
spl_autoload_register('Autoloader::service'); 



配置/自動加載磁帶機.php

class Autoloader { 
function config($class) { 
    $file = 'config/' . $class . '.php'; 
    if(file_exists($file)) { 
     require_once $file; 
    } 
} 
function controller($class) { 
    $file = 'presentation/controllers/' . $class . '.php'; 
    if(file_exists($file)) { 
     require_once $file; 
    } 
} 
function service($class) { 
    $file = 'model/services/' . $class . '.php'; 
    if(file_exists($file)) { 
     require_once $file; 
    } 
} 
} 
+1

錯誤消息告訴您需要解決問題的所有信息。你正在靜態調用非靜態函數。 – Maerlyn

+0

@Maerlyn你說得對,如果我只是仔細閱讀了一下。所有這些txt和大詞在經過一整天的編碼之後都會讓我感到不知所措:/它是有意義的,它有效,但它很奇怪,我讀的文檔都沒有顯示你必須實例化它。 – Aaron

回答

0

您需要創建一個Autoloader類的實例,然後傳遞它到註冊功能。

include("config/autoloader.php"); 
$autoloader = new Autoloader(); 
spl_autoload_register(array($autoloader, 'loader'));