原文地址laravel
一. 问题json
当咱们 clone下来一个laravel框架,接着就开始咱们表演,可是咱们根据业务需求须要建立一些自定义的文件夹,那么咱们该如何加载他们呢,如何避免这类错误[Symfony\\Component\\Debug\\Exception\\FatalThrowableError] Class 'tools\\alyduanxin\\api\_demo\\SmsDemo' not found
api
二:分三步来解决这个问题app
在项目文件夹的根目录下找到composer.json文件,在autoload里添加psr-4节点composer
"psr-4": { "tools\\": "tools/" }
接着执行框架
composer dump-autoload -o
三. 解释一下 composer dump-autoload 这条命令
less
下面是composer官方文档中关于dump-autoload命令的解释:性能
If you need to update the autoloader(类加载器)
because of new classes in a classmap package for example, you can use "dump-autoload
" to do that without having to go through an install or update.
Additionally, it can dump an optimized(优化)
autoloader that converts(转化) PSR-0/4 packages into classmap
ones for performance(性能)
reasons. In large applications with many classes, the autoloader can take up a substantial portion of every request's time. Using classmaps for everything is less convenient in development, but using this option you can still use PSR-0/4 for convenience and classmaps for performance.Options:
--no-scripts:
Skips the execution of all scripts defined in composer.json file.--optimize (-o):
Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.--classmap-authoritative (-a):
Autoload classes from the classmap only. Implicitly enables --optimize.--apcu:
Use APCu to cache found/not-found classes.--no-dev:
Disables autoload-dev rules.
其中官方推荐的参数是 -o,即 composer dump-autoload -o
这个命令能够将PSR-0/4自动加载成classmap来获取一个更快速的类加载器,推荐生产环境使用,可是,可能须要一点时间来运行,所以目前不是默认this