Laravel 5 如何包含 autoload.php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32575659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 how to include autoload.php
提问by Sam
I'm trying to include a path to autoload.php which is in
我正在尝试包含一个指向 autoload.php 的路径
vendor/autoload.php
the file trying to access it is in
试图访问它的文件在
public/this-file.php
I set the path to require_once '../vendor/autoload.php';
but it just throws the error -
我将路径设置为,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')
Does laravel offer a shortcode to access files in the vendor file
laravel 是否提供短代码来访问供应商文件中的文件
回答by Drown
You don't need to require autoload.php
in a Laravel application, it's already being required. You can just add more package in your composer.json
file or do a composer require
in the command line, and it should work.
你不需要autoload.php
在 Laravel 应用程序中 require,它已经被需要了。您可以在composer.json
文件中添加更多包或composer require
在命令行中执行 a ,它应该可以工作。
It is required in bootstrap/autoload.php
, if you don't believe me. ;)
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';
If it doesn't for some reason, try composer dump-autoload
, which fixes a lot of "requiring" issues in Laravel, especially when working with seeders and that sort of thing.
如果由于某种原因没有composer dump-autoload
解决,请尝试,它修复了 Laravel 中的许多“必需”问题,尤其是在使用播种机之类的时候。