php 自动加载错误:没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18406096/
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
Autoload Error: No such file or directory
提问by user2711055
I have included autoload.php in the header of my site
我在我的网站的标题中包含了 autoload.php
include 'vendor/autoload.php';
From this i am receiving the following errors on my site:
由此,我在我的网站上收到以下错误:
Warning: require_once(DIR/composer/autoload_real.php) [function.require-once]: failed to open stream: No such file or directory in /homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on line 5
Fatal error: require_once() [function.require]: Failed opening required 'DIR/composer/autoload_real.php' (include_path='.:/usr/lib/php5') in /homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php on line 5
警告:require_once(DIR/composer/autoload_real.php)[function.require-once]:无法打开流:第 5 行的 /homepages/6/d416629391/htdocs/leftovercheese/vendor/autoload.php 中没有这样的文件或目录
致命错误:require_once() [function.require]:在 /homepages/6/d416629391/htdocs/leftovercheese/ 中打开所需的“ DIR/composer/autoload_real.php”(include_path='.:/usr/lib/php5' )失败第 5 行的 vendor/autoload.php
My code is:
我的代码是:
// autoload.php generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit8be239f5caef32db03f87bb271ed6012::getLoader();
PHP Version: 5.2.17
PHP 版本:5.2.17
Any ideas?
有任何想法吗?
回答by Joseph Silber
You have to load vendor/autoload.php
, which will autoload that file for you:
您必须加载vendor/autoload.php
,它会为您自动加载该文件:
require_once __DIR__ . '/vendor/autoload.php';
This is assuming that your file is located at the same directory level as the vendor
directory.
这是假设您的文件与目录位于同一目录级别vendor
。
Otherwise, adjust.
否则,调整。
回答by reinaH
run composer install
跑 composer install
That will import your packages and create the vendor folder as well as the autoload script. Also, make sure your relative path is correct.
这将导入您的包并创建供应商文件夹以及自动加载脚本。另外,请确保您的相对路径是正确的。