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 Building Websites with PHP Slim Basics & Twig Templates Including & Rendering

I keep getting a Slim Application Error.

Slim Application Error The application could not run because of the following error:


Type: BadMethodCallException
Message: Method display is not a valid method
File: /home/ubuntu/workspace/vendor/slim/slim/Slim/App.php
Line: 124

#0 /home/ubuntu/workspace/index.php(11): Slim\App->__call('display', Array)
#1 /home/ubuntu/workspace/index.php(11): Slim\App->display('index.html')
#2 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 /home/ubuntu/workspace/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#4 /home/ubuntu/workspace/vendor/slim/slim/Slim/Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#5 /home/ubuntu/workspace/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /home/ubuntu/workspace/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 /home/ubuntu/workspace/vendor/slim/slim/Slim/App.php(438): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 /home/ubuntu/workspace/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 /home/ubuntu/workspace/vendor/slim/slim/Slim/App.php(332): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#10 /home/ubuntu/workspace/vendor/slim/slim/Slim/App.php(293): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#11 /home/ubuntu/workspace/index.php(18): Slim\App->run()
#12 {main}

composer version is 3.7 if that helps. my code is...

    require 'vendor/autoload.php';
    $config = ['settings' => ['displayErrorDetails' => true]];

    $app = new \Slim\App($config, array(
    'templates.path' => './test-folder'

    $app->get('/', function()  use($app){

    $app->get('/contact', function() use($app){


help! :c

<?php require 'vendor/autoload.php'; date_default_timezone_get('Asia/Seoul'); $config = ['settings' => ['displayErrorDetails' => true]];

$app = new \Slim\App($config);

$app->get('/', function()  use($app){

$app->get('/contact', function() use($app){


Well, i removed the arrays still nothing.

Also fixed $app->display to $app->render again sorry i'm also trying out new stuff. still doesn't work tho.

1 Answer

Chris Shaw
Chris Shaw
26,662 Points

Hi Aero Camacho,

As shown on the GitHub page, you need to return your rendered views otherwise the application won't know it has anything to render.

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

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

Happy coding!

I followed the stuff from the github page, it works perfectly now. Thanks!