Problem: Because I migrate an existing program to the slim framework, withRedirect has been implemented for the previous dynamic address. the code is as follows: {code ...} while many asynchronous requests are post, and after 301 to the new address, the post data is directly lost. I remember that redirection can carry...
Problem: Because I migrate an existing program to the slim framework, we have done withRedirect for the previous dynamic address. the code is as follows:
Ci = $ ci;}/*** Compatible URL middleware invokable class. ** @ param \ Psr \ Http \ Message \ RequestInterface $ request PSR7 request * @ param \ Psr \ Http \ Message \ ResponseInterface $ response PSR7 response * @ param callable $ next middleware * @ return \ Psr \ Http \ Message \ ResponseInterface * @ author Seven Du
**/Public function _ invoke (Request $ request, Response $ response, callable $ next) {$ app = $ request-> getQueryParam ('app '); $ mod = $ request-> getQueryParam ('mod'); $ act = $ request-> getQueryParam ('AC'); $ param = []; if ($ app! = Null) {$ param ['app'] = $ app;} if ($ mod! = Null) {$ param ['controller'] = $ mod;} if ($ act! = Null) {$ param ['action'] = $ act;} $ router = $ this-> ci-> get ('router '); $ queryParam = $ request-> getQueryParams (); unset ($ queryParam ['app'], $ queryParam ['mod'], $ queryParam ['AC']); $ uri = $ router-> pathFor ('apps ', $ param, $ queryParam); if ($ uri! = $ Router-> pathFor ('apps ', [], $ queryParam )) {// permanently redirect paths with a trailing slash // to their non-trailing counterpart return $ response-> withRedirect (string) $ uri, 301 );} return $ next ($ request, $ response) ;}// END class CompatibleURL
However, many asynchronous requests are post, and after 301 to the new address, the post data is directly lost,
I remember that redirection can carry post data, but in slim, how do I set it from Response? Ask!
Thank you ?!
Reply content:
Problem: Because I migrate an existing program to the slim framework, we have done withRedirect for the previous dynamic address. the code is as follows:
Ci = $ ci;}/*** Compatible URL middleware invokable class. ** @ param \ Psr \ Http \ Message \ RequestInterface $ request PSR7 request * @ param \ Psr \ Http \ Message \ ResponseInterface $ response PSR7 response * @ param callable $ next middleware * @ return \ Psr \ Http \ Message \ ResponseInterface * @ author Seven Du
**/Public function _ invoke (Request $ request, Response $ response, callable $ next) {$ app = $ request-> getQueryParam ('app '); $ mod = $ request-> getQueryParam ('mod'); $ act = $ request-> getQueryParam ('AC'); $ param = []; if ($ app! = Null) {$ param ['app'] = $ app;} if ($ mod! = Null) {$ param ['controller'] = $ mod;} if ($ act! = Null) {$ param ['action'] = $ act;} $ router = $ this-> ci-> get ('router '); $ queryParam = $ request-> getQueryParams (); unset ($ queryParam ['app'], $ queryParam ['mod'], $ queryParam ['AC']); $ uri = $ router-> pathFor ('apps ', $ param, $ queryParam); if ($ uri! = $ Router-> pathFor ('apps ', [], $ queryParam )) {// permanently redirect paths with a trailing slash // to their non-trailing counterpart return $ response-> withRedirect (string) $ uri, 301 );} return $ next ($ request, $ response) ;}// END class CompatibleURL
However, many asynchronous requests are post, and after 301 to the new address, the post data is directly lost,
I remember that redirection can carry post data, but in slim, how do I set it from Response? Ask!
Thank you ?!
I don't understand, but 30X indicates server redirection. This status code is returned by the server response. Php can be set through the header function.
First, these parameters should be processed before 301 or later. a good design should be done before 301. after processing, a redirection will be made to display the relevant results page, with only necessary query parameters, in this case, the POST parameter should not be retrieved, but the results should be displayed directly based on the query parameters.