Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

itangsanjana
itangsanjana
2,685 Points

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.

itangsanjana
itangsanjana
2,685 Points

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

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

2 Answers

Alexander Sobakar
Alexander Sobakar
10,044 Points

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();
David Pennington
David Pennington
15,713 Points

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.