I have to do something wrong.
I need a route that parses and combines an array of parameters GETto redirect to another route waiting for GETparameters.
I was hoping this would work when I pass $search_paramsas part of the method pathFor():
$app->get('/search', function ($request, $response, $args) {
$api = $this->APIRequest->get($request->getAttribute('path'),$request->getQueryParams());
$args['data'] = json_decode($api->getBody(), true);
return $this->view->render($response, 'search.html.twig', $args);
})->setName('search');
$app->get('/advanced_search', function ($request, $response, $args) {
return $this->view->render($response, 'advanced_search.html.twig', $args);
});
$app->post('/advanced_search', function ($request, $response, $args) {
$settings = $this->get('settings');
$qp = $request->getParsedBody();
$search_params = array();
$search_params['q'] = $qp['query'];
$url = $this->router->pathFor('search', $search_params);
return $response->withStatus(302)->withHeader('Location', $url);
});
But this did not add the array $search_paramsas GET parameters. I understand that if a route was /searchexpecting arguments in a URL with something like {q}, it would get caught, but I need to add an unknown group of parameters GET.
My workaround is to do the following, manually using http_build_query()to add the parameters GETas a string to the route URL:
$app->get('/search', function ($request, $response, $args) {
$api = $this->APIRequest->get($request->getAttribute('path'),$request->getQueryParams());
$args['data'] = json_decode($api->getBody(), true);
return $this->view->render($response, 'search.html.twig', $args);
})->setName('search');
$app->get('/advanced_search', function ($request, $response, $args) {
return $this->view->render($response, 'advanced_search.html.twig', $args);
});
$app->post('/advanced_search', function ($request, $response, $args) {
$settings = $this->get('settings');
$qp = $request->getParsedBody();
$search_params = array();
$search_params['q'] = $qp['query'];
$url = $this->router->pathFor('search')."?".http_build_query($search_params);
return $response->withStatus(302)->withHeader('Location', $url);
});
. - Slim 3 ?
POST GET? HTTP- 307 withStatus() , - , /search, .
.