Symfony2请求调用了两次

时间:2014-06-24 15:27:39

标签: symfony firefox symfony-2.3

我遇到Symfony2重复请求的问题。

下面的示例控制器应该只返回一个透明的gif。但是,当请求URL时,会有两个“点击”。对于请求而doSomething()被称为两次而不是一次。

// simple action in a controller, ends up being called twice
public function testAction() {
    doSomething();

    $response = new Response(base64_decode('R0lGODlhAQABAIAAAOrq6gAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='));
    $response->headers->set('Content-Type', 'image/gif');
    return $response;
}

如果我更改了响应行,那么它会设置一个空白响应然后停止发生(即doSomething()只被调用一次):

// with a blank response it is only called once
public function testAction() {
    doSomething();

    $response = new Response('');
    $response->headers->set('Content-Type', 'image/gif');
    return $response;
}

如果我删除标题行,则只调用一次:

// without the Content-Type header it is only called once
public function testAction() {
    doSomething();

    $response = new Response(base64_decode('R0lGODlhAQABAIAAAOrq6gAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='));
    return $response;
}

最后(这里是妙语)...如果我将Content-Type更改为text / html(或text / css),那么它只会被调用一次!

// if a text content type is used, it is only called once
public function testAction() {
    doSomething();

    $response = new Response(base64_decode('R0lGODlhAQABAIAAAOrq6gAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='));
    $response->headers->set('Content-Type', 'text/html');
    return $response;
}

但是对于真实内容和正确的标题,它会被调用两次(并且两个相同的条目出现在Web分析器中)。如果使用php模板渲染内容也会出现同样的问题(我还没试过过twig)。

可能导致这种情况的原因以及如何防止(或解决)?


编辑:总而言之,这是一个Firefox错误,与Symfony完全无关。

0 个答案:

没有答案