Laravel 5如何包含autoload.php

时间:2015-09-14 23:58:53

标签: php laravel

我正在尝试在

中包含autoload.php的路径
vendor/autoload.php

尝试访问它的文件位于

public/this-file.php

我将路径设置为require_once '../vendor/autoload.php';,但它只会抛出错误 -

Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory

Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/opt/php55/lib/php')

laravel是否提供了一个短代码来访问供应商文件中的文件

1 个答案:

答案 0 :(得分:10)

您不需要在Laravel应用程序中要求autoload.php,它已经被要求了。您可以在composer.json文件中添加更多包,或在命令行中执行composer require,它应该可以正常工作。

bootstrap/autoload.php需要,如果你不相信我的话。 ;)

/*
|---------------------------------------------------------------------  -----
| Register The Composer Auto Loader
|-------------------------------------------------------------------------    -
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

如果由于某种原因没有,请尝试composer dump-autoload,其中修复了许多"要求" Laravel中的问题,特别是在与播种者等合作时。