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

Adam Siwiec
Adam Siwiec
12,070 Points

Help with Slim, Twig, and PHP, in my project.

I'm currently working on a redesigning my website with PHP, currently I have a rough sketch laid out. The only problem is I'm try to D.R.Y why code with PHP and Twig templates, but whenever I run it on my local server it never fully runs. I know everything on my computer and server is fine because I have run my project from workspaces on it and it worked. All my software (used in my working and failing projects) is up to date and I ran my localhost in chrome. Can anyone take a look at my source code and tell me if there is anything wrong with it?

index.php:

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


$app = new \Slim\Slim( array(
  'view' => new \Slim\Views\Twig()
));

 $view = $app->view();
$view->parserOptions = array(
    'debug' => true
);
$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
);

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

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

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

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

$app->run();
?> 

main.twig :

<!DOCTYPE html> 
<html>
    <head>
    <meta charset= "utf-8">
    <title> Adam Siwiec</title>   
    <link rel="stylesheet" href="css/style.css"> 
    <link href='https://fonts.googleapis.com/css?family=Roboto|Montserrat' rel='stylesheet' type='text/css'> 
        </head>

    <body>
        <header>
            <section class = "title">
            <a href="index.html" >
            <h1>Adam Siwiec</h1>
            <h2> 
                Interestingly Complementary
            </h2>
            </a>
            </section>

                <ul id = "navigation">
                    <li><a href="me.html">Vision</a></li>
                    <li><a href="vid.html">Library</a></li>
                    <li><a href="case.html">Cases</a></li>
                </ul>

        </header>

        {%block content%}
        {%endblock content%}



        <footer>

         <p> Adam Siwiec 2016 </p>

        </footer>

    </body>

</html>

I have a couple more "content" pages that inputs content to main.twig, but there is nothing wrong with them.

1 Answer

Maybe you should check Slim User Gide to ensure that you start you server correctly and give to it proper file.