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 trialHenrik Christensen
Python Web Development Techdegree Student 38,322 PointsSlim / Twig
Hi,
I followed the videos in "building websites with PHP" but I had to modify A LOT (I feel) during the videoes since the teacher is using v.2 and I'm using v.3.
I can make it work just fine using "Slim/php-view" but it started to fail when we got to the .twig templates - then I switched to the the "slim/twig-view" instead but still not working..
// Create Slim app
$app = new \Slim\App();
// Fetch DI Container
$container = $app->getContainer();
// Register Twig View helper
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig('path/to/templates', [
'cache' => 'path/to/cache'
]);
// Instantiate and add Slim specific extension
$basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($c['router'], $basePath));
return $view;
};
// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->view->render($response, 'profile.html', [
'name' => $args['name']
]);
})->setName('profile');
// Run app
$app->run();
It seems to fail when I change this: $app->get('/hello/{name}' to this $app->get('/'
I have no idea why this happen and I hope someone can help me.
1 Answer
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsSolved the problem myself - seemed like I had to remove two dependencies to make it work >.<