views:

75

answers:

1

I have an app that receives a request from another app. It detects a value on the query string, checks that value against a cached value and, if they don't match, it needs to clear its cache and reload the page (establishing a new cache). Unfortunately, I can't find a way to tell Symfony to redirect to the current page in exactly the same format (protocol, URI path, query string, etc.). What am I missing? This is all happening in a filter on isFirstCall().

Thanks.

+1  A: 

We have done this in a filter.

It is a bit hacky but here is an example of doing the redirect in a filter...you'll have to do the testing of the cache yourself...

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();   
  }
}
johnwards
Like you, I couldn't find a way to make the request object do this directly while still executing the filters on the redirect (which ruled out the use of `forward()` in my case). The `getUri()` method did exactly what I needed since it includes all of the relevant information about the request. When I first saw it, I was afraid it wouldn't include the query string. Thanks.
Rob Wilkerson