且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

致命错误:在中找不到类 'DotenvDotenv'

更新时间:2022-06-21 06:38:06

请确保您使用的是 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.