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

荒凉一梦 提交于 2019-12-04 04:53:40

问题


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 why..

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

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.


回答1:


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.




回答2:


check if you have "vlucas/phpdotenv" : "~2.2" in "require" tag in composer file. if you don't then add that plugin and open your terminal and run "composer dump-autoload" then run "composer update". and just to be safe run "composer dump-autoload" once again to refresh all the file paths.

and, if you do have phpdotenv plugin then add that plugin in "require" then just run the dump-autoload command.




回答3:


You just need to remove complied.php from bootstrap\cache and it will works fine.

Thanks




回答4:


just remove/delete the vendor folder and reinstall with the -> composer install.



来源:https://stackoverflow.com/questions/37199237/fatal-error-class-dotenv-dotenv-not-found-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!