我在设置响应的编码时遇到了问题。 试过:Slim Framework:设置响应的编码
- $ app-> contentType('text/html; charset = utf-8');
- header(“Content-Type:application/json”);
- $ app-> response() - > header('Content-Type','application/json; charset = utf-8');
我卡住了...: -/
编辑
我已经下载了Slim/slim-skeleton
通过作曲家。
我需要在返回JSON我Route.php
:
$app->get('/getStoresByBounds', function() use ($app, $stores) {
$app->contentType('application/json');
$myStores = $stores->getStores();
$app->response()->write(json_encode($myStores));
$app->stop();
});
我不能在航线使用它 - 它说: “未定义类”。试图在路线中使用($ app)',但它不起作用。 –
您是否添加了使用Slim \ Slim;在你班级的顶部?或者你可以显示一些示例代码? – Swag
当我尝试你的梯子的例子,它仍然说Slim是一个未定义的类。我使用最新版本的Slim,版本3.2.1。在版本2.6.1(我的最后一个项目)中没有问题... :-( –