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

部署后,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

  • 写回答

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"
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 YOLOv5在进行trainpy训练后为什么会出现这种情况(语言-python)
  • ¥15 关于远程桌面的鼠标位置转换
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!