Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP Composer Autoload Issue

Options
  • 19-05-2015 10:42am
    #1
    Registered Users Posts: 1,987 ✭✭✭


    Hi all, maybe I'm being silly and either not doing something correct or I'm just doing it all wrong, I've introduced composer into an existing project and it's downloading and creating the vendor directory fine and all the packages are available via their namespaces etc.

    Now I've tried to add my existing classes to the composer autoload option but can't seem to get them to load.

    All class files in the 'classes' directory are named '{classname}.php', so for example a class called 'Login' would have a file name of 'Login.php' in the classes directory.

    Directory structure:
    index.php
       media/
       site/
           classes/
               Login.php
           vendor/
           composer.json
    

    Composer Autoload Section:
    "autoload": {
       "psr-0": {
           "site\\": "classes/"
       }
    }
    

    Any help is greatly appreciated?!


Comments

  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Got it to work eventually.

    Changed this:
    "autoload": {
       "psr-0": {
           "site\\": "classes/"
       }
    }
    

    To:
    "autoload": {
       "psr-0": {
           "": "classes/"
       }
    }
    

    Then ran 'composer dump-autoload' which seems to have solved the issue.


Advertisement