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 trialChristiaan Quyn
14,706 PointsSlim Application Error - When I run my index.php file
Hey guys, so I'm following this course coding on JetBrains PhpStorm ( instead of workspaces) and everything has been working pretty smooth so far until I followed along with this video. I'm stuck and confused and I'd greatly appreciate anyone who can look at my code and help me.
Here's what shows up on my browser when I run index.php
Slim Application Error The application could not run because of the following error:
Details
Type: RuntimeException Message: Cannot set the Smarty lib directory : . Directory does not exist. File: C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\views\Smarty.php Line: 104 Trace
0 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\views\Smarty.php(87): Slim\Views\Smarty->getInstance()
1 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\View.php(255): Slim\Views\Smarty->render('about.twig', NULL)
2 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\View.php(243): Slim\View->fetch('about.twig', NULL)
3 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Slim.php(757): Slim\View->display('about.twig')
4 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\index.php(26): Slim\Slim->render('about.twig')
5 [internal function]: {closure}()
6 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
7 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch()
8 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call()
9 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()
10 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()
11 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()
12 C:\Users\Christiaan\PhpstormProjects\CompanyPortfolio\index.php(33): Slim\Slim->run()
13 {main}
Here's my code
index.php
<?php
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('Asia/Colombo');
/*
$log = new Logger('name');
$log->pushHandler(new StreamHandler('app.log', Logger::WARNING));
$log->addWarning('Foo');
*/
$app = new \Slim\Slim( array (
'view' => new \Slim\Views\Smarty()
));
$view = $app->view();
$view->parserOptions = array(
'debug' => true,
);
$view->parserExtensions = array(
new \Slim\Views\TwigExtension(),
);
$app->get('/', function () use($app){
$app->render('about.twig');
});
$app->get('/contact', function () use($app){
$app->render('contact.twig');
});
$app->run();
main.twig
<!doctype html>
<html lang="en">
<head>
{% block head %}
<meta charset="utf-8">
<title> {% block title %}Ralph Waldo Emerson{% endblock title %}</title>
<meta name="description" content="Ralph Waldo Emerson">
<meta name="author" content="Treehouse">
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../css/master.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../js/global.js"></script>
{% endblock head %}
</head>
<body>
<!--
<div id="feedback" class="success">
<h3>Success!</h3>
<p>You're reading all about Emerson.</p>
</div>
-->
<header>
<h1>Ralph Waldo Emerson</h1>
<nav>
<a href="about.twig" class="selected">About</a>
<a href="contact.twig">Contact</a>
</nav>
</header>
<div class="emerson">
{% block hero %} <img src="../images/emerson.jpg" alt="Picture of Ralph Waldo Emerson">{% endblock hero %}
</div>
<main>
{% block content %}
{% endblock content %}
</main>
<footer>
{% block footer %}
<p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p>
<nav>
<a href="about.twig" class="selected">About</a>
<a href="contact.twig">Contact</a>
</nav>
{% endblock footer %}
</footer>
</body>
</html>
about.twig
<!doctype html>
<html lang="en">
<head>
{% block head %}
<meta charset="utf-8">
<title>Ralph Waldo Emerson</title>
<meta name="description" content="Ralph Waldo Emerson">
<meta name="author" content="Treehouse">
<link rel="stylesheet" href="../css/master.css">
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../js/global.js"></script>
{% endblock head %}
</head>
<body>
<!-- <div id="feedback" class="fail">
<a class="dismiss">Dismiss</a>
<h3>Oops!</h3>
<p>Looks like you forgot to enter your email address.</p>
</div>
-->
<header>
<h1>Ralph Waldo Emerson</h1>
<nav>
<a href="about.twig">About</a>
<a href="contact.html" class="selected">Contact</a>
</nav>
</header>
<div class="emerson">
<img src="../images/emerson.jpg" alt="Picture of Ralph Waldo Emerson">
</div>
<main>
<strong>Contact</strong>
<h2>Ralph Waldo Emerson</h2>
<p>Unfortately, Ralph Waldo Emerson has been deceased for over 100 years so he's not particularly expediant at replying to email but you can make an attempt below. However, if you require face to gravestone contact you can visit his remains at:</p>
<address>
<h4>Sleepy Hollow Cemetery</h4>
<p>34 Bedford Street<br>
Concord, MA 01742, United States<br>
<a href="https://www.google.com/maps/place/Sleepy+Hollow+Cemetery/@42.464126,-71.343098,15z/data=!4m2!3m1!1s0x0:0x9c41d0f83df689a6?sa=X&ei=ZCgLVZb5Io_hoASc7oHwCQ&ved=0CH0Q_BIwCw">Google Map</a></p>
</address>
<form>
<fieldset>
<input type="text" placeholder="Full Name">
<input type="email" placeholder="Email Address">
<textarea placeholder="Your message..."></textarea>
</fieldset>
<input type="submit" class="button">
</form>
</main>
<footer>
<p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p>
<nav>
<a href="about.twig">About</a>
<a href="contact.html" class="selected">Contact</a>
</nav>
</footer>
</body>
</html>