2

I have a simple PHP web app with the following structure:

/         (composer.json .htaccess ...)  
/Core/    (Router.php, Controller.php ...)    
/App/     (/Controllers, /Models, /Views ...)    
/Public/  (index.php ...)  
/Vendor/  (autoload.php /composer ...)  

The codes runs without issue on my local server.

When I copy it to a live server and make the necessary changes to .htaccess in route I get the following error: Fatal error: Class 'Core\Router' not found in.... I have tried 3 different hosts but no luck.

The issue seems to be to do with the composer autoload function not loading in the namespaces and classes using psr-4. I have this set up in my composer.json file:

{
"autoload": {
    "psr-4": {
         "Core\\": "Core/",
         "App\\": "App/"
    }
}

The code for my project is on GitHub at

https://github.com/imoprojects/upbook

I am new to programming in an MVC structure and also with using composer in this way.

If anyone could assist with what maybe happening, I would really appreciate it.

Cheers, Ian

IMO
  • 307
  • 1
  • 3
  • 12
  • Have you did `composer install` on the server after copying your project? If you copy files including vendor folder do `composer dump` to refresh autoloader. – Chris Cynarski Feb 06 '17 at 17:15
  • 1
    As a sidenote you should not commit your vendor directory. That's supposed to be automatically generated via `composer install` on every deploy. You are supposed to commit your `composer.lock` if any. – apokryfos Feb 06 '17 at 17:17
  • @apokryfos for some reason composer does not generate a composer.lock file when I run composer install . I assumed it was because I am not pulling in any third party libraries? Thank you for the advice, I will ignore it from the commit next time – IMO Feb 06 '17 at 17:41
  • @IMO your particular case there wouldn't be one generated because you're not requiring any additional packages. That's why I added the "if any" part at the end. – apokryfos Feb 07 '17 at 07:34

1 Answers1

6

You configure this:

"Core\\": "Core/",

... but your classes are at:

core

This will only work in case insensitive file systems.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Thank you @Álvaro that has been causing me so much trouble. Is there a standard that I should be following in terms of naming folders and files? I am new to development and I am trying to learn good practice. – IMO Feb 06 '17 at 17:38
  • Great thanks, I will read the docs this time :) ... lots to learn! – IMO Feb 06 '17 at 17:43
  • WOW what a pity, it was driving me crazy for the past 12 hours... Never thought such a simple difference between OS can have such a huge impact. Even worse only one of hundreds of files had a wrong case!!!! I am gonna dance this evening. – Michał Kuczek Nov 26 '20 at 14:12