PHP adding custom namespace using autoloader from composer

吃可爱长大的小学妹 提交于 2019-11-28 06:52:53

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!