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 & Rendering

Does not render contact.html

Hi my beloved treehouse community :). I need some help on this. I followed the instructions on this video exactly as it is shown, and still when I type in my browser the URL "localhost/project/contact" i get the Not Found message. But the index.html is rendering just fine when i leave it to "localhost/project/"

here is my index.php code:

<?php require 'vendor/autoload.php';

$app = new Slim\Slim();

$app->get('/', function() use($app){ $app->render('index.html'); });

$app->get('/contact', function() use($app) { $app->render('contact.html'); });

$app->run();

2 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Here is my code, which is work:

$app = new \Slim\Slim( array(
    'view' => new \Slim\Views\Twig()
));   //new slim object instance

$view = $app->view();
$view->parserOptions = array(
    'debug' => true
);

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension()
);

//define a HTTP GET route
$app->get('/', function () use($app){
    $app->render('about.twig');
})->name('home');

$app->get('/contact', function () use($app){
    $app->render('contact.twig');
})->name('contact');

Or you can check my project on the link below - https://github.com/SergeyPodgornyy/Treehouse-PHP_Website

Thank's for the answer. The reason it did not work is that i forgot the .htaccess in the root folder. Dumb mistake from me. Thank u anyway. It is frustrating how something so minor can take up a lot of time figuring out.