在Slim / Userfrosting中设置响应头

时间:2015-08-26 18:40:50

标签: php json slim

有一个想要返回json的php文件,但是不断得到html字符编码错误...当我导航到路径时没有输出。

MarkersController.php(getMarkersJSON())

$markers = array();
while ($rows = mysqli_fetch_assoc($result)) {
    //Assuming "lat" is column name in tester table. Please change it if required.
    $lat= $rows['lat'];
    //Assuming "lng" is column name in tester table. Please change it if required.
    $lng= $rows['lng'];

    $markers = array('lat' => $lat, 'lng' => $lng);
}

$app = new \Slim\Slim();
$app->response->headers->set('Content-Type', 'application/json');
echo json_encode($markers);

}

在index.php中路由

$app->get('/markers/', function () use ($app) {
    $controller = new UF\MarkersController($app);
    return $controller->getMarkersJSON();

0 个答案:

没有答案