The autoload section of a composer.json file

116 views Asked by At

I have created a composer library.

I have one folder:

Models

Inside that is 1 file, it has a namespace declared TestJames

In my composer.json file I have:

"autoload": {
    "psr-0": { "TestJames": "Models/" }
} 

Firstly, I have no idea what the psr-0 bit means. Secondly, I am unsure of the order of bits and bobs.

Is there a documentation specifically for this part, and what am I doing wrong?

1

There are 1 answers

1
Jordi Martínez On BEST ANSWER

PSR-0 is a standard for autoloading, but it's deprecated (if you can, use PSR-4). See more in here.

For doc about composer autoload look here

It seems to be better:
"autoload": {
    "psr-0": { "TestJames\\": "Models/" }
}

Has you executed "composer update"? It creates your vendor directory and you autoload.php file.

Also important is that you require vendor/autoload.php in your execution flow before you try to acces to this class.