donglin317704291 2016-05-20 19:03
浏览 86
已采纳

在PHP中使用名称空间::找不到致命错误Core \ App


I made an MVC project in local (WAMP) and it runs perfectly. But when i deploy it in a web server apears this error:

Fatal error: Class 'Core\App' not found in home/dmlink/public_html/public/index.php on line 14

This is the code of the line 14:

13: spl_autoload_register('autoload_classes');
14: $app = new \Core\App;
15: $app->render();

The structure of the project:

  • app : Here are the controllers, models, and views.
  • core: Here are the core files.
  • public: Since this directory runs the app.

I got the same version in the web server like in localhost:

  • php 5.5
  • apache 2.4

This is the complete code of index:

define('PROJECT_PATH', dirname(__DIR__));
define('APP_PATH', PROJECT_PATH . '/app');

function autoload_classes($class_name){
    $file = PROJECT_PATH . '/' . str_replace('\\', '/', $class_name) . '.php';
    if (is_file($file)) {
        include_once $file;
    }
}

spl_autoload_register('autoload_classes');
$app = new \Core\App;
$app->render();

Any idea that is causing this error ThankS for all by the way.

  • 写回答

2条回答 默认 最新

  • duanji1924 2016-06-02 17:28
    关注

    Finally i found the error, and was very simple!.

    The error was the name of the directories where the classes are. I just rename the directory 'Core' instead 'core' .... And thats it.

    Thanks for all!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?