Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Composer Autoload Issue

  • 19-05-2015 10:42AM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    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, Registered Users 2 Posts: 1,991 ✭✭✭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