Slimframework + PHP-View

Asked

Viewed 301 times

0

I did the download library Php-View to use together with Slim Framework 3.x, but I am not able to make the return of view.

// Get container
$container = $app->getContainer();

// Register component on container
$container['view'] = function ($container) {
  return new \Slim\Views\PhpRenderer('App/resources/views');
};

$app->get('/', function($request, $response) {
  $tes = new \App\Teste(); // Usando Eloquent ORM
  $tes->nome = "OI";
  return $this->view->render($response, "home.php", array("obj" => $tes->nome));
});
$app->run();

If I make one var_dump($tes), I receive the object normally, but if I try to call the view only get the error

A website error has occurred. Sorry for the Temporary inconvenience.

1 answer

1

I found the mistake;

The same was in the declaration of path to the archives

return new \Slim\Views\PhpRenderer('App/resources/views');

There was one last bar missing / after views.

return new \Slim\Views\PhpRenderer('App/resources/views/');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.