Slim路由段由正斜槓定義,不能與點互換。但是,您可以將邏輯添加到路由關閉中,或將路由條件添加到多個路由。
在封閉:
$app->get('/user/:methodtype', function ($methodtype) {
if ($path = explode($methodtype, '.')) {
if ($path[1] === 'json') {
// Something to do with json...
} elseif ($path[1] === 'xml') {
// Something to do with xml...
}
}
});
或者使用路徑的條件下,爲每個所以他們是互相排斥的:
// JSON requests
$app->get('/user/:methodtype', function ($methodtype) {
// Something to do with json...
})->conditions(array('methodtype' => '.json$'));
// XML requests
$app->get('/user/:methodtype', function ($methodtype) {
// Something to do with xml...
})->conditions(array('methodtype' => '.xml$'));
有一個接受這個頭:HTTP://www.w3 .org/Protocols/rfc2616/rfc2616-sec14.html – Tuim
在這個項目中,我需要讓用戶確定輸出格式 – Reza1607