I use psr-4
autoloader from composer:
"autoload": {
"psr-4": {
"DG\Munchkin\": "src/DG/Munch/"
}
}
This loads classes from /var/www/html/xxx/vendor/yyy/src/DG/Munch
But how can I load classes from /var/www/html/xxx/
?
I wrote my own autoloader, but when I require vendor/autoload.php
(composer autoload) and my autoloader, it won't work until I create instance of a class in my own autoloader.
The
src
directory would be in your project root. Its on the same level asvendor
directory is.If you define
this will not load classes from
/var/www/html/xxx/vendor/yyy/src/DG/Munch
, like you stated.Because your project structure is:
The
DGMunchkin
namespace would map to classes inside/var/www/html/xxx/src/DG/Munch
and not inside/var/www/html/xxx/vendor/yyy/src/DG/Munch
.But how can I load classes from /var/www/html/xxx/?
Define the paths in the composer.json (inside /var/www/html/xxx/) of your project:
or load the composer autoloader in your index.php or during it's bootstrap and add the paths manually:
Referencing: https://getcomposer.org/doc/04-schema.md#autoload