Here is my folder structure:
Classes
- CronJobs
- Weather
- WeatherSite.php
I want to load WeatherSite class from my script. Im
You actually don't need custom autoloader, you can use PSR-4.
Update your autoload
section in composer.json
:
"autoload": {
"psr-4": {
"Classes\\Weather\\": "Classes/CronJobs/Weather"
}
}
To explain: it's {"Namespace\\": "directory to be found in"}
Don't forget to run composer dump-autoload
to update Composer cache.
Then you can use it like this:
include(LIBRARY .'autoload.php');
$weather = new Classes\Weather\WeatherSite();