简体   繁体   中英

Composer psr-4 autoload not working after deployment

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 App\routes;

class Routing
{
    private $parameters = [];

    public function GetMC($Getroute){
    }

}

File structure on server:

在此处输入图片说明

I have excluded the vendor map from the tree

okay... I have fixed it.

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"
  }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM