致命错误:在中找不到类 'DotenvDotenv' [英] Fatal error: Class 'DotenvDotenv' not found in

查看:127
本文介绍了致命错误:在中找不到类 'DotenvDotenv'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我很困惑,我不知道我做错了什么,这告诉了我致命错误:在

Hello guys I am so confused I dont know what I am doing wrong this told me Fatal error: Class 'DotenvDotenv' not found in

但我不明白为什么..

$dotenv = new DotenvDotenv(dirname(dirname(dirname(dirname(__DIR__)))));
$dotenv->load();

我的结构是下一个,在文件 index.php 中我调用 Dotenv 我也使用过使用 DotenvDotenv;但它也不起作用.

My structure is the next and in the file index.php is where I am calling Dotenv also I used use DotenvDotenv; but it doesnt work too.

推荐答案

请确保您使用的是 Dotenv aftervendor/autoload.php 加载.

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 为:

And I had defined DIR_VENDOR in config.php as:

define('DIR_VENDOR', __DIR__.'/vendor/');

所以最后,在 index.php 中,我会:

So finally, in index.php, I would have:

// Startup
require_once(DIR_SYSTEM . 'startup.php');

// dotenv
$dotenv = new DotenvDotenv(__DIR__);
$dotenv->load();

所以startup.php加载vendor/autoload.php,它加载vlucas/phpdotenv,之后我们就可以找到DotenvDotenv.

So startup.php loads vendor/autoload.php, which loads vlucas/phpdotenv, after which we can then find DotenvDotenv.

这篇关于致命错误:在中找不到类 'DotenvDotenv'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆