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 For Our Project

Ulrike Pechmann
Ulrike Pechmann
18,211 Points

My Solution with Slim 3.8

I tried to make it in Slim 3.8.x so here is the Code that works for me.

2 Answers

Rob Adams
Rob Adams
3,460 Points

May 2018 - Slim v3.10

Here's the code I was able to get to work for this video. It's a combination of Hampton's 'require' and 'date/time' fix and the code on the front page of the Slim site. Good luck! (This video really does need an update.)

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

  use \Psr\Http\Message\ServerRequestInterface as Request;
  use \Psr\Http\Message\ResponseInterface as Response;

  $app = new \Slim\App;
  $app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");

    return $response;
  });

  $app->run();
?>