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

Again 404 Error!

I have made everything exactly the same as teacher is doing but nothing is changing! There is 404 Error every time i refresh.

Here's my code:

<?php

require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('Europe/Vienna');

// use Monolog\Logger; // Every Logger after it means: Monolog\Logger
// use Monolog\Handler\StreamHandler;

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

// Slim
$app = new \Slim\Slim();

$app->get('localhost:8888/ProjectUsingComposer/', function(){
  echo "Hello, this is the home page.";
});

$app->get('/contact', function(){
  echo "Fell free to contact us.";
});

$app->run();

also I've tried to change first get with only slash and there is no difference.

2 Answers

I copied your code and created a new "index.php" file in Workspaces and pasted your code in and it worked fine ... so it doesn't seem to be a problem with your index.php file ... I would ask: did the previous exercise work? ..the one before this one where you printed out your name? Mine didn't until I added a line of code to the top of the .htaccess file suggested by another member on here (here it is: RewriteEngine On RewriteLog "/path/to/rewrite.log" RewriteLogLevel 9) ... If the previous exercise DID work for you, then perhaps closing Workspaces and relaunching might be worth a try. In any event, perhaps looking elsewhere other than your code in your index.php file would be the best option because as I say, your code ran fine (I used the '/' path as the first argument for the "get" method as 'localhost' etc gave me a lengthy Slim-generated error)

I was just doing this same thing... I was refreshing the preview from the previous example... which held /hello/Brandon at the end of the URL....

Given that we just changed the redirects to / and /contact.... then the /hello ... is no longer a valid page.

I spent longer than I'd like to admit trying to figure this out. lol