Search code examples
phpframeworksrequestforwardlithium

Lithium redirect send request data


Trying to build a controller method that can redirect and send the request data along with it. Controller/route redirect doesn't seem to have anything that can achieve this.

This question gave a new approach but I'm unable to figure out how to redirect to the specified page instead of rendering on the current.

$forward = Libraries::instance("controllers", "Main", [
     'request' => $this->request
]);
return $forward($this->request, ['action' => 'view']);

The route tests don't seem to provide any insight either, how can I go about achieving url redirect while still retaining the request data?


Solution

  • From within a controller:

    $this->redirect(['AnotherController::anotherAction', '?' => $this->request->query], ['exit' => true]);
    

    $this->request->data can't be forwarded. Browser location redirects can only specify the query string. You could maybe render a page with a form that contains the data in input html elements and submit the form on load. Or you could stash the data in a session or somewhere server side and retrieve it on the next request.