du2229
2018-01-15 02:56
浏览 1.3k
已采纳

部署后,Composer psr-4自动加载不起作用

I have my own little MVC framework and I use composer psr-4 autoloading.

On my own computer it works perfectly fine, but when I deployed it to my Ubuntu server it did not work anymore. (it doesn't find any classes anymore) I have tried a lot of things but it just won't work whatever I try...

What I have tried:

  • composer dump-autoload
  • composer update
  • removing everything and uploading again
  • searching on internet for a couple hours... :(

This is my composer.json:

{
  "autoload": {
    "psr-4": {
      "App\\": "app",
      "Core\\": "core",
      "Magister\\": "vendor/Magister"
    }
  },
  "require": {
    "philo/laravel-blade": "^3.1"
  }
}

I just don't get it why it's not working on my server.... I am using an other version of php on my server: 7.1, and I am using 5.6 on my computer, but this shouldn't make any difference right?

How do I fix this problem? I just don't get it why it happens.... :(

EDIT:

My code:

Index.php:

<?php

require "core/app.php";

$app = new \Core\App();

echo $app->start();

app.php:

<?php

namespace Core;

require "./vendor/autoload.php";

class App
{

    function start()
    {
        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL ^ E_DEPRECATED);

        $MC = new Routing();
        // This is where it fails. Get the error: "class Core\Routing not found"

Routing.php:

<?php

namespace Core;

Use Appoutes;

class Routing
{
    private $parameters = [];

    public function GetMC($Getroute){
    }

}

File structure on server:

enter image description here

I have excluded the vendor map from the tree

图片转代码服务由CSDN问答提供 功能建议

我有自己的小MVC框架,我使用composer psr-4自动加载。

在我自己的计算机上它运行得很好,但是当我将它部署到我的Ubuntu服务器时它不再起作用了。 (它再也找不到任何课程了)我已经尝试了很多东西,但是无论我尝试什么都不行......

我尝试了什么:< / strong>

  • composer dump-autoload
  • composer update
  • 删除所有内容并重新上传
  • 在互联网上搜索了几个小时... :(

    这是我的composer.json:

      {
    “autoload”:{
    “psr-4”:{
    “App \\”:“app”,
    “Core \\”  :“core”,
    “Magister \\”:“vendor / Magister”
    } 
    },
    “require”:{
    “philo / laravel-blade”:“^ 3.1”
    } \  n} 
       
     
     

    我只是不明白为什么它不能在我的服务器上工作.... 我在我的服务器上使用其他版本的php: 7.1,我在我的计算机上使用5.6,但这不应该有任何区别吗?

    如何解决这个问题?我只是不明白为什么会发生这种情况。 ... :(

    编辑:

    我的代码:

    的index.php:

     <代码>&LT; PHP 
     
    req?  uire“core / app.php”; 
     
     $ app = new \ Core \ App(); 
     
    echo $ app-&gt; start(); 
       
     \  n 

    app.php:

     &lt;?php 
     
    namespace Core; 
     
    require“./vendor/autoload.php";
    nnclass  App 
     {
     
    函数start()
     {
     ini_set('display_errors',1); 
     ini_set('display_startup_errors',1); 
     error_reporting(E_ALL ^ E_DEPRECATED); 
     
      $ MC = new Routing(); 
     //这是失败的地方。 得到错误:“类Core \ Routing not found”
       
     
     

    Routing.php:

     &lt;?  php 
     
    namespace核心; 
     
    使用App 
    outes; 
     
    class Routing 
     {
     private $ parameters = []; 
     
    公共函数GetMC($ Getroute){
    } 
     \ 在服务器上的文件结构: 
     
     

    我从树中排除了供应商地图

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doulu2576 2018-01-15 16:30
    已采纳

    okay... I have fixed it.

    I don't know why and how it works, but it works... :D

    I have changed my composer.json to this:

    {
      "autoload": {
        "psr-4": {
          "App\\": "app/",
          "Core\\": "core/",
          "Magister\\": "vendor/Magister/"
        },
        "classmap": [
          "app/",
          "core/",
          "vendor/Magister/"
        ]
      },
      "require": {
        "philo/laravel-blade": "^3.1"
      }
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongma7796 2018-09-27 18:06

    If you want to use psr-4 you need to capitalize your directories to

    app
    - Modules
    - Controllers
    - Views
    -- Layouts
    ...
    

    Please refer to this post as to why your autoloading isn't working.

    评论
    解决 无用
    打赏 举报
  • 在远方。 2020-11-25 17:22

    多谢啊,终于找到原因了。

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题