2010-06-14 77 views
4

我有一个应用程序接收来自另一个应用程序的请求。它检测查询字符串的值,根据缓存值检查该值,如果它们不匹配,则需要清除缓存并重新加载页面(建立新的缓存)。不幸的是,我找不到一种方式告诉Symfony以完全相同的格式(协议,URI路径,查询字符串等)重定向到当前页面。我错过了什么?这一切都发生在isFirstCall()的过滤器上。Symfony是否可以重新加载页面请求?

谢谢。

回答

4

我们已经在一个过滤器中完成了这项工作。

这是一个有点哈克但这里是在过滤器中做重定向的例子......你必须做你自己的高速缓存的测试...

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(); 
    } 
} 
+0

和你一样,我无法找到一种方法,使请求对象做到这一点直接,同时仍然执行对重定向过滤器(这排除了使用'进( )'在我的情况下)。 'getUri()'方法正是我所需要的,因为它包含了有关请求的所有相关信息。当我第一次看到它时,我担心它不会包含查询字符串。谢谢。 – 2010-06-15 12:00:14

1

如果你想重定向,你可以这样做:

if (true===$redirect) 
{ 
    return $this->getContext()->getController()->redirect($request->getUri()); 
} 
+0

确切地说,在一个过滤器中你必须使用'$ this-> getContext() - > getController() - > redirect();' – 2013-04-10 08:34:40

+0

@MichalTrojanowski,谢谢。 (我粘贴了我的控制器的原始版本。) – 2013-04-10 09:09:44

相关问题