【问题标题】:My Default Controller Can Not Find the Parent Controller我的默认控制器找不到父控制器
【发布时间】:2023-04-08 15:17:01
【问题描述】:

我的应用程序在开发环境中运行良好。将其上传到生产服务器后,出现以下错误:

解析错误:语法错误,意外的 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 从位于 core 文件夹下的 MY_Controller 扩展而来。出于某种原因,生产环境中的所有这些问题,我都没有在我的本地主机中得到它。因此,home 是默认控制器。

这个错误会阻止应用程序运行,我根本想不通。任何帮助将不胜感激。

【问题讨论】:

  • 要么告诉我们哪一行是第 27 行(并发布第 1-26 行),要么只是发布 config.php 文件 - 它会将这个问题从“阅读并计算出你想要的”变成“发现致命错误”,这是一个更容易的答案:P
  • 您确实更改了生产配置文件中的 base_URL 对吗?你的 .htaccess 文件呢?
  • 您的生产环境中运行的是哪个 PHP 版本?
  • 是的,我更改了 base_url;生产服务器具有 PHP 版本 5.2.17。我的开发环境有 PHP 5.3.1

标签: php codeigniter codeigniter-2


【解决方案1】:

我猜你的生产服务器正在运行 PHP

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

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

【讨论】:

  • 生产服务器的 PHP 版本为 5.2.17。我的开发环境有 PHP 5.3.1。我会试试你的建议。
  • 我不得不将我的文件从 Frontend_controller.php 重命名为 Frontend_Controller.php。因此,“function __autoload($class)”与 5.2.17 兼容
猜你喜欢
  • 2017-02-17
  • 1970-01-01
  • 2015-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-03
  • 1970-01-01
相关资源
最近更新 更多