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

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Index.html will not load in browser

Hi,

I am unable to get index.html to load in the browser after attempting to include/render it. I was stuck on this over a month ago, gave up and came back only to get stuck at the same spot again. Can anyone help me? Thanks.

Here is my code for index.php:

<?php

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

use Monolog\Logger;
use Monolog\Handler\Streamhandler;

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

$app = new \Slim\Slim();

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

$app->run();

MOD: edited to format code.

3 Answers

try updating your code by adding the parenthesis:

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

get is a method in the Slim class. It has to have () with information passed to the method contained within the ().

If you are working in Workspaces, please create a fork snapshot by opening the Workspace, clicking on the camera icon in the upper right corner, following the steps to create and open the snapshot. Then post the url here. I can then open the entire project and take a look.

If you are not working in Workspaces. please post the revised code in its entirety.

In looking at the code again, it appears we are both missing a semicolon after 'contact.html'. It should be 'contact.html';

I made a number of changes to make it match my code that does work. I could not get it to work in Workspaces, but I did not do the project in Workspaces so there may be some installations that need to be done to work. Try this to see if it works for you. you will need to fork the snapshot with the link on the upper right of the snapshot.

https://w.trhou.se/iklk58mrgn

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Thanks for taking the time to help me try to figure this out. I did fork the snapshot and found that I am still unable to load the page. Maybe it is simply an issue with Workspace. Did you only make changes to index.php? What changes did you make?

I think that I may have to start over again from scratch (without Workspace) at this point. If it is working for you, it should also work for me. On the bright side, at least then I'll really retain what I have learned so far:-)

Cheers-

I will try loading the project onto my computer and see what happens later tonight.