致命错误:找不到类"Dotenv \ Dotenv" [英] Fatal error: Class 'Dotenv\Dotenv' not found in
问题描述
大家好,我很困惑,我不知道我在做什么错,这告诉了我 致命错误:找不到类'Dotenv \ Dotenv'
Hello guys I am so confused I dont know what I am doing wrong this told me Fatal error: Class 'Dotenv\Dotenv' not found in
但是我不明白为什么.
$dotenv = new \Dotenv\Dotenv(dirname(dirname(dirname(dirname(__DIR__)))));
$dotenv->load();
我的结构是下一个结构,并且在文件index.php中,我在其中调用Dotenv,我也曾经使用过Dotenv \ Dotenv;但这也行不通.
My structure is the next and in the file index.php is where I am calling Dotenv also I used use Dotenv\Dotenv; but it doesnt work too.
推荐答案
从vendor/autoload.php
加载后,请确保您正在使用Dotenv.
Be sure that you are using Dotenv after loading from vendor/autoload.php
.
例如,我使用的是OpenCart,其中包含文件startup.php
:
For example, I was using OpenCart, in which contained a file startup.php
with:
// Autoloader
if (file_exists(DIR_VENDOR . 'autoload.php')) {
require_once(DIR_VENDOR . 'autoload.php');
}
我在config.php
中将DIR_VENDOR
定义为:
define('DIR_VENDOR', __DIR__.'/vendor/');
最后,在index.php
中,我将:
// Startup
require_once(DIR_SYSTEM . 'startup.php');
// dotenv
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
因此startup.php
加载vendor/autoload.php
,它加载vlucas/phpdotenv
,然后我们可以找到Dotenv\Dotenv
.
So startup.php
loads vendor/autoload.php
, which loads vlucas/phpdotenv
, after which we can then find Dotenv\Dotenv
.
这篇关于致命错误:找不到类"Dotenv \ Dotenv"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!