2012-10-11 137 views
0

我的應用程序在開發環境中完全正常工作。一旦我把它上傳到我的生產服務器,我得到了以下錯誤:我的默認控制器無法找到父控制器

Parse error: syntax error, unexpected T_FUNCTION, expecting ‘)’ in /home/fjamal/public_html/*/anyname/application/config/config.php on line 27

的錯誤指的是下面的代碼:

spl_autoload_register(function($class) 
{ 
if (strpos($class, 'CI_') !== 0) 
{ 
    if (file_exists($file = APPPATH . 'core/' . $class . EXT)) 
    { 
    include $file; 
    } 
    elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT)) 
    { 
    include $file; 
    } 
} 
}); 

如果我改變了上面的代碼到舊版本:

function __autoload($class) 
{ 
if (strpos($class, 'CI_') !== 0) 
{ 
    if (file_exists($file = APPPATH . 'core/' . $class . EXT)) 
    { 
    include $file; 
    } 
    elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT)) 
    { 
    include $file; 
    } 
} 
} 

我得到的跟隨着克錯誤:

Fatal error: Class ‘Frontend_Controller’ not found in /home/fjamal/public_html/**/anyname/application/controllers/home.php on line 4

誤差的說明:我的控制器從Frontend_Controller駐留在庫文件夾延伸。 Frontend_Controller從駐留在覈心文件夾下的MY_Controller擴展而來。出於某種原因,在生產環境中的所有這些問題,我不明白它在我的本地主機。因此,家是默認控制器。

此錯誤阻止應用程序運行,我根本無法弄清楚它。任何幫助將不勝感激。

+0

要麼告訴我們哪一行是第27行(並且是第1-26行),或者只是發佈'config.php'文件 - 它會將這個問題從「讀取和解決你想要的問題」轉變爲「找到致命的錯誤「,這是一個更容易的答案:P – Joe

+0

您確實在生產配置文件中更改了base_URL?和你的.htaccess文件? –

+0

哪個PHP版本在您的生產環境中運行? –

回答

1

我猜想,你的生產服務器與PHP運行< 5.3

代碼使用匿名函數,他們已經在PHP 5.3.0引進

解決方案:創建一個名爲功能並用它作爲回調。

+0

生產服務器的PHP版本爲5.2.17。我的開發環境有PHP 5.3.1。我會嘗試你的建議。 – user311509

+0

我不得不將我的文件從Frontend_controller.php重命名爲Frontend_Controller.php。因此,「function __autoload($ class)」與5.2.17兼容 – user311509