Używam Silex przez jeden dzień i mam pierwsze "głupie" pytanie. Jeśli mam:Jak uzyskać wszystkie parametry GET w Silex?
$app->get('/cities/{city_id}.json', function(Request $request, $city_id) use($app) {
....
})
->bind('city')
->middleware($checkHash);
Chcę uzyskać wszystkie parametry (city_id) zawarte w middleware:
$checkHash = function (Request $request) use ($app) {
// not loading city_id, just the parameter after the ?
$params = $request->query->all();
....
}
Tak, jak mogę dostać city_id (zarówno nazwa parametru i jego wartość) wewnątrz oprogramowanie pośredniczące. Będę miał 30 akcji, więc potrzebuję czegoś użytecznego i możliwego do utrzymania.
Czego mi brakuje?
wielkie dzięki!
Rozwiązanie
Musimy dostać te dodatkowe parametry $ request-> Atrybuty
$checkHash = function (Request $request) use ($app) {
// GET params
$params = $request->query->all();
// Params which are on the PATH_INFO
foreach ($request->attributes as $key => $val)
{
// on the attributes ParamaterBag there are other parameters
// which start with a _parametername. We don't want them.
if (strpos($key, '_') != 0)
{
$params[ $key ] = $val;
}
}
// now we have all the parameters of the url on $params
...
});
wygląda -> middleware() już nie istnieje? – Tobias