可能是我误解了某些东西,但如果请求是重定向,是否可以检测到控制器的方法(GET)?我想做类似的事情:Laravel 4检测重定向
if(Request::statusCode() == '304') {}
谢谢!
可能是我误解了某些东西,但如果请求是重定向,是否可以检测到控制器的方法(GET)?我想做类似的事情:Laravel 4检测重定向
if(Request::statusCode() == '304') {}
谢谢!
根据Laravel Request Api,Laravel没有任何statusCode()
方法。
http://laravel.com/api/4.1/Illuminate/Http/Request.html
但是,您可以使用PHP的http_response_code
方法来检测响应代码。
if(http_response_code() == '304')
{
// do something
}
参考:
http://www.php.net/manual/en/function.http-response-code.php
我得到了同样的问题。搜索后,最后传递一个变量与重定向(我使用laravel 5)。
public function method1(){
//detect its redirect or not
if(Session::get('isRedirected')){
//this is redirect from method2
}
else{
//this is regular call
}
}
public function method2(){
return redirect('method1')->with('isRedirected',1);
}
事实上,它不工作:o在这两种情况下200状态代码返回:( –