我已经按照作曲家安装了 slim framework 3 和 twig 模板。当我调用函数http://localhost/elec/helloo/sandesh时,它会显示 Hello, Sandesh,如 slim 3 文档中所示。
但是当我尝试调用视图页面(在模板文件夹内)时。
它显示一个错误页面 Slim Application Error The application could not run because of the following error错误描述
代码工作(显示 hello , {name} 来自函数)
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
代码错误(从函数调用视图页面时显示错误)
$settings = [
'settings' => [
'displayErrorDetails' => true,
],
];
$app = new Slim\App($settings);
// Get container
$container = $app->getContainer();
// Register component on container
$container['view'] = function ($container) {
return new \Slim\Views\PhpRenderer("templates/");
};
// Render Twig template in route
$app->get('/helloo/{name}', function ($request, $response, $args) {
return $this->view->render($response, 'view1.html', [
'name' => $args['name']
]);
})->setName('profile');
路径详细信息
elec>
>>cache
>>templates
>>>view1.html
>>vender
>>.htaccess
>>composer.json
>>composer.lock
>>index.php