Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJeremy Dyck
12,013 PointsError With Dotenv When Previewing
I have been following along with the videos up until this point. When I try previewing I get the following error. Not sure where the issue is.
Notice: Use of undefined constant Dotenv - assumed 'Dotenv' in /home/treehouse/workspace/inc/settings.php on line 2
Fatal error: Uncaught Error: Class 'Dotenv' not found in /home/treehouse/workspace/inc/settings.php:2 Stack trace: #0 /home/treehouse/workspace/inc/bootstrap.php(6): require_once() #1 /home/treehouse/workspace/index.php(2): require_once('/home/treehouse...') #2 {main} thrown in /home/treehouse/workspace/inc/settings.php on line 2
''' <?php $dotenv = Dotenv/Dotenv::create(DIR); $dotenv->load();
/*
- Handle Exceptions */ function exception_handler($e) { die($e->getMessage()); } set_exception_handler("exception_handler");
/*
- Set up database connection */ try { $db = new PDO( 'sqlite:'.DIR.'/database.db' ); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch ( \Exception $e ) { echo 'Error connecting to the Database: ' . $e->getMessage(); exit; }
/*
- Set access to components from \Symfony\Component\HttpFoundation\
- 1. Session
- 2. Request
- 3. Redirect */
// 1. session \Symfony\Component\HttpFoundation\Session $session = new \Symfony\Component\HttpFoundation\Session\Session(); $session->start();
// 2. request \Symfony\Component\HttpFoundation\Request function request() { return \Symfony\Component\HttpFoundation\Request::createFromGlobals(); }
// 3. redirect \Symfony\Component\HttpFoundation\Response function redirect($path, $extra = []) { $response = \Symfony\Component\HttpFoundation\Response::create(null, \Symfony\Component\HttpFoundation\Response::HTTP_FOUND, ['Location' => $path]); if (key_exists('cookies', $extra)) { foreach ($extra['cookies'] as $cookie) { $response->headers->setCookie($cookie); } } $response->send(); exit; } '''