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 Routing in Slim

Christopher Edrian Espiritu
Christopher Edrian Espiritu
11,635 Points

Getting trouble with routing '/hello' to 'index.php', I think my code is right tried it on workspaces and is working.

What did I get wrong?

index.php
<?php
require 'Slim.php';

$app = new \Slim\Slim();

/*  add your code below this line */
$app->get('/hello', function() use($app){
  $app->render('index.php');
});
/* add your code above this line */

$app->run();
Christopher Edrian Espiritu
Christopher Edrian Espiritu
11,635 Points

I got it using the following code:

<?php
require 'Slim.php';

$app = new \Slim\Slim();

/*  add your code below this line */

$app->get('/hello', function() use($app){
  echo 'index.php';
});

/* add your code above this line */

$app->run();

The question was " Add a 'get' route '/hello' to index.php "

I guess either the question has been misworded or I did't understand it correctly :)

Niclas Valentiner
Niclas Valentiner
8,947 Points

I just want to say how much this means.

I got stuck in the exact same way, I looked in the including and rendering video and basically copy pasted Hamptons code (with the changes required) and got told it was wrong. It is clearly not wrong but the question doesn't show up as "print out the STRING of index.html". No, it bloody says route to index.html, a file name.

Am I the only one who thinks it's a logical conclusion that we're supposed to render the whole file then? We didn't echo anything in the routing for about 7 videos, got taught a better way to handle output from a route and then we're faced with a vaguely worded quiz question that just says "Oh, you're wrong."

TL;DR: Thanks a lot for sharing the solution, Christopher. I'd probably sooner ragequit than realized it wanted me to dumb everything down.