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.
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
.
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.
You just need to remove complied.php
from bootstrap\cache
and it will works fine.
Thanks
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