我的默认控制器无法找到父控制器

时间:2012-10-11 22:44:03

标签: php codeigniter codeigniter-2

我的应用程序在开发环境中工作得很好。一旦我将其上传到我的生产服务器,我收到以下错误:

  

解析错误:语法错误,意外的T_FUNCTION,期待')'   /home/fjamal/public_html/*/anyname/application/config/config.php   在第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;
  }
 }
}  

我收到以下错误:

  

致命错误:找不到类'Frontend_Controller'   /home/fjamal/public_html/**/anyname/application/controllers/home.php   第4行

错误说明:我的控制器从位于Libraries文件夹中的Frontend_Controller扩展。 Frontend_Controller从MY_Controller扩展而来,它位于核心文件夹下。出于某种原因,生产环境中的所有这些问题,我都没有在我的localhost中得到它。因此,home是默认控制器。

此错误会阻止应用程序运行,我根本无法理解。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我猜你的生产服务器是用PHP< 5.3

运行的

您的代码使用匿名函数,它们已在PHP 5.3.0中引入

解决方案:创建一个命名函数并将其用作回调。