有一个想要返回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();