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 & Running Slim

Slim 3

Slim 3.0.0 released, any update to the video soon? Thanks!

You probably have already figured this out, but I merely included the new required code:

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

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

    return $response;
});
$app->run();

Everything else in this video works exactly the same.

I just in to PHP :) I'll try both. Thanks!

thanks - wasn't sure what was wrong.. Antonio's code below works.

2 Answers

New code is:

<?php

require 'vendor/autoload.php';

$app = new \Slim\App();

$app->get('/hello/{name}', function($req, $rsp, $args ){
    echo "Hello {$args['name']}";
});

$app->run();

Thank you!

Amazing, thank you Alexander

I installed Slim 3 also and found that the syntax is significantly different from that of version 2. In order to follow on with the video, this is what I did in workspaces to remove v3 and install version 2:

treehouse:~/workspace$ composer remove slim/slim

treehouse:~/workspace$ composer update

treehouse:~/workspace$ composer require slim/slim:~2.0

You can find The Slim version 2 docs as shown on the video here.