1
所以我想讓用戶在向服務器運行一個休息API請求時請求.xml或者.json響應。 (很像twitter)基於url的瘦和不同響應類型
但我不相信下面的方式是最好的方式,因爲它意味着重複的代碼,當然有更好的方法來允許.xml或.json響應。
$app->get('/books/:id.xml', function ($id) use ($app) {
$app->render('/xml/books.xml', array('id' => $id));
});
$app->get('/books/:id.json', function ($id) use ($app) {
$app->render('json/books.json', array('id' => $id));
});
OR
// Define app routes
$app->get('/hello/{name}.{type}', function ($request, $response, $args) {
//return $response->write("Hello " . $args['name']);
if($args['type'] == 'xml')
{
return 'this is xml';
}
var_dump(parse_url($_SERVER['REQUEST_URI']));
});
如果有誰知道如何做到這一點,那將是巨大的。
我已經使用Slim不應該苗條的框架能夠做到這一點? – RussellHarrower
據我所知,Slim本身不能進行內容協商。 –