Search code examples
phphttp-redirectslim

Slim 3 withRedirect problem and parameters


I use Slim 3 and i want pass values to withRedirect

$app->get('/users/create/', function($request, $response, $args) use ($user){
    return $this->view->render($response, 'usuarios/crear.html', ['data'=> []]);
})->setName('root');

and I redirect

return $response->withRedirect($this->router->pathFor('root', ['data'=> $input]));

and redirect but no show the new data. thx for read!


Solution

  • The second parameter of the pathFor() method is for routes with named placeholders like /users/{id}.

    The 3. parameter of pathFor($name, array $data = [], array $queryParams = []) is for the query parameters.

    Example

    return $response->withRedirect($this->router->pathFor('root', [], ['data'=> $input]));