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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jeremy Dyck](https://secure.gravatar.com/avatar/eff11f03da4f9ab4f87a1c58c86cd64e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jeremy 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; } '''