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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:20:40  来源:igfitidea点击:

Laravel 5 how to include autoload.php

phplaravel

提问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.phpin a Laravel application, it's already being required. You can just add more package in your composer.jsonfile or do a composer requirein 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 中的许多“必需”问题,尤其是在使用播种机之类的时候。