dongqiao6730 2018-09-29 06:08
浏览 69
已采纳

SLIM错误::在服务器上托管SLIM应用程序时找不到AuthController

I have a REST api app using SLIM framework. Below is my app dir structure enter image description here

Below is structure in my controllers dir

enter image description here

Authcontroller.php is in Auth folder.

Below are namespaces given to ActionController and Authcontroller enter image description here enter image description here

Both controllers (Action and Auth) are defined in container as below in the mainapp enter image description here

Above app is working fine on my localhost ,but when i upload same to my server, it get below error on above line 58 enter image description here

Please help me here , i am going mad,have changed around 3 hosting servers(SHARED-HOSTING),but still same error. PLEASE HELP!!

  • 写回答

1条回答 默认 最新

  • duanquan4451 2018-09-29 08:50
    关注

    If your deployment server is Linux, mostly, because path is case-sensitive.

    If your composer.json contains section such as below

    ...
    "autoload": {
        "psr-4": {
            "App\\": "app"
        },
    },
    ...
    

    Composer PSR-4 autoloading expect to find class

    \App\Controllers\Auth\AuthController
    

    in file

     app\Controllers\Auth\AuthController.php
    

    but it can not find it because yours is

     app\controllers\Auth\AuthController.php
    

    Since your development machine seems to use Windows which by default is case-insensitive,

     app\controllers\Auth\AuthController.php
    

    equals to

     app\Controllers\Auth\AuthController.php
    

    Which is why it works on your development machine but not on deployment server.

    So the solution is to rename any directory/files to match its case and also make sure that all files is copied to deployment server.

    After you change directory/filename case, run

    $ composer dump-autoload

    So new autoload file is generated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?