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

contact.html is not working but index.html works any one help!! what is wrong with my code

<?php

require __DIR__ . '/vendor/autoload.php';

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

// During instantiation
$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();


?>

18 Answers

Dean Friedland
Dean Friedland
2,453 Points

Please click link below for answer:

The Answer!!!

If your project is in a folder in your localhost environment, then you need localhost/folder/about.html.

You cannot render index.html because you have index.php. The project has the main landing page as about.html. Try changing index.html to about.html. If you really have index.html in your file tree, try changing its name to about.html as well.

thanks for the response it is working now but when i click the about page is going dead 404 not found the file

i tried the link to about.html <a href="about.html">it is still going dead end it is not working

if i enter this url localhost/ it is working ok but localhost/about.html it is not working

i modified the link to <a href="about.html">

okey solved!! but one more problem localhost/contact is not working

'''php <?php

require DIR . '/vendor/autoload.php';

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

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

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

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

$app->run();

?>

'''

<?php

require __DIR__ . '/vendor/autoload.php';

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

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

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

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



$app->run();


?>
Dean Friedland
Dean Friedland
2,453 Points

Same issue. I hit "preview workspace" and the page comes up fine but if I click on either heading tab (index.html or contact.html) it goes 404 :(

Dean Friedland
Dean Friedland
2,453 Points

''' <?php require DIR . '/vendor/autoload.php'; date_default_timezone_set ('America/New_York');

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

$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(); '''

Dean Friedland
Dean Friedland
2,453 Points
<?php
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set ('America/New_York');

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

$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();

Here is a link to a post I did when I took this course. I think it discusses the issues and extent of the solutions that I discovered.

https://teamtreehouse.com/community/inconsistent-routing-and-helper-variable-output

Dean Friedland
Dean Friedland
2,453 Points

Thanks but I found out from another member that information had changed and had not been updated in the video. I had to change two naming conventions on the contact and index files. Then it worked.

Please post the solution here or mark the best answer.

Dean Friedland post your solutions so that i can see what changed

Nikhil Khandelwal
Nikhil Khandelwal
9,371 Points

I have tried nearly everything what all the answers were saying including Dean Friedland answer. but nothing is working for '/contact'.

tried changing to /contact, contact in <a> tags in html files but none working for /contact rendering.

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