Fatal error: Class 'Dotenv\Dotenv' not found in

前端 未结 7 679
悲哀的现实
悲哀的现实 2021-01-18 17:10

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

But I dont understand

相关标签:
7条回答
  • 2021-01-18 17:46

    Be sure that you are using Dotenv after loading from vendor/autoload.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');
    }
    

    And I had defined DIR_VENDOR in config.php as:

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

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

    // Startup
    require_once(DIR_SYSTEM . 'startup.php');
    
    // dotenv
    $dotenv = new Dotenv\Dotenv(__DIR__);
    $dotenv->load();
    

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

    0 讨论(0)
提交回复
热议问题