我有一个应用程序接收来自另一个应用程序的请求。它检测查询字符串上的值,根据缓存值检查该值,如果它们不匹配,则需要清除其缓存并重新加载页面(建立新缓存)。不幸的是,我找不到告诉 Symfony 以完全相同的格式(协议、URI 路径、查询字符串等)重定向到当前页面的方法。我错过了什么?这一切都发生在isFirstCall()
.
谢谢。
我有一个应用程序接收来自另一个应用程序的请求。它检测查询字符串上的值,根据缓存值检查该值,如果它们不匹配,则需要清除其缓存并重新加载页面(建立新缓存)。不幸的是,我找不到告诉 Symfony 以完全相同的格式(协议、URI 路径、查询字符串等)重定向到当前页面的方法。我错过了什么?这一切都发生在isFirstCall()
.
谢谢。
我们已经在过滤器中做到了这一点。
这有点hacky,但这是在过滤器中进行重定向的示例......您必须自己进行缓存测试......
class invalidateCacheFilter extends sfFilter {
public function execute($filterChain) {
$redirect=true;
if($redirect===true)
{
$request = $this->getContext()->getRequest();
/**
This is the hacky bit. I am pretty sure we can do this in the request object,
but we needed to get it done quickly and this is exactly what needed to happen.
*/
header("location: ".$request->getUri());
exit();
}
$filterChain->execute();
}
}
如果你想重定向,你可以这样做:
if (true===$redirect)
{
return $this->getContext()->getController()->redirect($request->getUri());
}