问题:因为我是已有程序迁移到slim框架上,所以,真对以前的动态地址做了withredirect,代码如下:
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 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('act'); $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['act']); $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
而很多一些异步请求为post,301到新的地址后,直接丢失了post的数据,如图:
我记得重定向是可以携带post数据的,但是在slim中,这么从response设置呢?请教!
感谢?!
回复内容: 问题:因为我是已有程序迁移到slim框架上,所以,真对以前的动态地址做了withredirect,代码如下:
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 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('act'); $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['act']); $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
而很多一些异步请求为post,301到新的地址后,直接丢失了post的数据,如图:
我记得重定向是可以携带post数据的,但是在slim中,这么从response设置呢?请教!
感谢?!
没看明白,但是30x代表的应该就是服务器重定向吧,这个状态码是服务器response回来的应该是无疑的。php可以通过header函数来设置。
首先这些参数应该在301之前处理还是之后处理,好的设计应该是在301之前处理,处理完之后做个重定向,展示相关的结果页面,只带上必要的查询参数,这时不应该再去取post参数了,而是直接根据查询参数展示结果。