【发布时间】:2017-02-24 09:59:22
【问题描述】:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
require '../src/config/db_standings.php';
$app = new \Slim\App;
require '../src/routes/ppg.php';
require '../src/routes/standings.php';
$app->run();
所以这是我的index.php 文件,我不明白为什么它的行为方式只是加载最后一条所需的路线。在这种情况下,只有standings.php。无论我最后添加什么路线,它只会加载最后一条路线,并且找不到其他页面。我做错了什么?
排名.php
<?php
Header('Content-Type: application/json; charset=UTF-8');
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/standings', function(Request $request, Response $response){
$sql = "SELECT * FROM standings";
try {
$db = new db_standings();
$db = $db->connect();
$stmt = $db->query($sql);
$standings = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
$json = json_encode($standings, JSON_UNESCAPED_UNICODE);
echo($json);
} catch(PDOException $e) {
echo '{"error": {"text": '.$e->getMessage().'}';
}
});
ppg.php
<?php
Header('Content-Type: application/json; charset=UTF-8');
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/ppg', function(Request $request, Response $response){
echo 'BANANAS';
});
【问题讨论】: