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

Myles Hyson
Myles Hyson
8,853 Points

Using Sublime

Using Sublime 3 for this part of the video. I downloaded all the necessary things and I think the code is right. Get an error message instead of the echo string for both the home and contact page. Can somebody please help?

<?php

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

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

$app = new \Slim\Slim();

$app->get('/', function(){
    echo "Hello this is the Home Page";
});

$app->get('/contact', function(){
    echo "Hello this is the Contact Page";
});

$app->run();
?>

and here is the .htaccess file

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

1 Answer

you are missing a little bit on both lines. Add use($app) to both lines like this:

<?php
$app->get('/', function() use($app) {
Myles Hyson
Myles Hyson
8,853 Points

Awesome Thanks! That worked. They didn't use that in the video. What does the use($app) do?

I think they did use it in the video, at least the one that I watched. It is built in function that is used for aliasing. http://php.net/manual/en/language.namespaces.importing.php

This course does not work without it and the code I wrote when I took the course has it.

Please mark best answer so that other people know the issue is resolved.