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

Rendering Error

I'm in the course slim-basics-twig-templates and as I follow the instructions comparing with the slimframework page there are some differences so I'm trying to render the index.html page and I get this error: Slim Application Error

The application could not run because of the following error:

Details

Type: BadMethodCallException

Message: Method render is not a valid method

File: C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\App.php

Line: 126

Trace

0 C:\xampp7\htdocs\OmesviDev\src\index.php(71): Slim\App->__call('render', Array)

1 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)

2 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)

3 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\Route.php(356): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)

4 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))

5 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\Route.php(334): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))

6 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\App.php(515): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))

7 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(117): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))

8 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\App.php(406): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))

9 C:\xampp7\htdocs\OmesviDev\src\vendor\slim\slim\Slim\App.php(314): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))

10 C:\xampp7\htdocs\OmesviDev\src\index.php(84): Slim\App->run()

11 {main}

My code is as follows:

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

use Monolog\Logger; use Monolog\Handler\StreamHandler;

use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response;

// Ajustes de configuracion $config['displayErrorDetails'] = true; // habilita el modo de desarrollo $config['addContentLengthHeader'] = false; // permite ajustar el largo del contenido para el encabezado

$app = new \Slim\App(['settings' => $config]);

// Contenedor para crear dependencias que se necesitan en el proyecto $container = $app->getContainer();

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

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

$app->run();