您好我在渲染页面时遇到问题,希望有人可以帮我解决。 我已经尝试更改目录结构以及创建一个具有类似代码的新项目,但对我来说没有任何作用。
routes.php文件
<?php
$app->get('/home' , function() {
return $this->view->render($response,'home.twig');
});
app.php
<?php
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\App([
'settings'=> [
'displayErrorDetails' => true,
]
]);
$container = $app->getContainer();
// Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig(__DIR__.'/../resources/views', [
'cache' => __DIR__.'../cache',
]);
// Instantiate and add Slim specific extension
$view->addExtension(new Slim\Views\TwigExtension(
$container['router'],
$container['request']->getUri()
));
return $view;
};
require __DIR__ . '/../app/routes.php';
的index.php
<?php
require __DIR__ . '/../bootstrap/app.php';
$app->run();
答案 0 :(得分:0)
闭包需要routes.php中的额外参数:
// Render Twig template in route
$app->get('/home', function ($request, $response) {
return $this->view->render($response, 'home.twig');
});