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

PHP Building Websites with PHP Slim Basics & Twig Templates Including & Rendering

Shahzain Hashmi
Shahzain Hashmi
2,360 Points

Index.html isn't showing up

index.html isn't showing up when previewing the php website. Could someone read my code and tell me why?

Shahzain Hashmi
Shahzain Hashmi
2,360 Points
<?php

require 'vendor/autoload.php';
date_default_timezone_set('America/New_York');

//$log = new Monolog\Logger('name');
//$log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING));
//
//$log->addWarning('Foo');

$app = new /Slim/Slim();

$app->get('/',function() use($app){
  $app->render('index.html');
});

$app->get('/contact', function() {
  echo 'Feel free to contact us';
});

$app->run();

2 Answers

I think by default the render method looks in a 'templates' folder for the file. So depending on where you saved the 'index.html', you may have to move up a directory or two. I already had a html file I was working with and I saved it in the same root as 'index.php'. I had to move up a directory in the render method. Use '../' to move up one directory. For example: "$app->render('../index.html');" This may or may not help you but it's something I learned when I had the same issues. On a side note, I'm using Eclipse IDE not workspaces so that may or may not be a contributing factor.

Harsh Verma
Harsh Verma
659 Points

Thanx , solved the problem !

Michael Soileau
Michael Soileau
9,431 Points

Too many variables. Is your .htaccess file setup correctly?

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]