【问题标题】:Symfony 2.5 prints cache headerSymfony 2.5 打印缓存头
【发布时间】:2014-06-26 06:27:18
【问题描述】:

我正在使用 Symfony 2.5。我从控制器返回我的视图模板页面。

但是,当我呈现页面时,它会将原始缓存显示为<body> 标记中的第一部分。

HTTP/1.0 200 OK Cache-Control: no-cache Date: Thu, 26 Jun 2014 06:07:05 GMT  []

我用谷歌搜索发现this answer(与我的问题相似)和this answer(大致相同)。

所以我一一尝试了以下所有方法。但没有任何效果。

return $this->render('MyBookBundle:Section:splash.html.php' , $this->data);

echo $this->renderView('MyBookBundle:Section:splash.html.php' , $this->data);
return new Response();

$displaypage =  $this->renderView('MyBookBundle:Section:splash.html.php' , $this->data);
return new Response( $displaypage );

$displaypage =  $this->render('MyBookBundle:Section:splash.html.php' , $this->data);
return new Response( $displaypage->getContent() );

我的网页处于最简单的阶段。

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
</head>
<body>
    <div>Hello World</div>
</body>
</html>

这些方法仍然没有奏效。有人可以指导我正确的方向吗?

【问题讨论】:

  • 您的网络服务器是 apache2 吗?如果您查看源代码(不是使用调试器,而是通过进入页面源代码),这些数据是写在页面的最顶部还是真的在 &lt;body&gt; 标记之后?
  • 是的。这是正确的。我使用的是 Apache 2,数据紧跟在&lt;body&gt; 标记之后。

标签: php html symfony twig


【解决方案1】:

嗯,我不知道是否遵循正确的答案,但它对我有用。希望它可以帮助像我这样的新手。

在我的控制器中,我对其他控制器进行了一些forward 调用以获取所需的数据。 在那些控制器(曾经被动态调用的)中,我返回了一个响应对象。这是造成问题的原因。但是,只要我返回纯字符串,缓存显示问题就消失了。

理想情况下,我必须从控制器的 Action 方法返回响应对象。但是,在这种情况下,它在没有返回响应对象的情况下工作。

我是 Symfony2 的新手,我尝试 google 了一下,但找不到任何差异或原因。如果有人能启发,那就太好了。

附言我认为我应该将那些不提供页面但仅在后台工作的控制器更改为服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 2017-07-05
    • 2012-09-29
    • 2011-03-10
    • 2018-04-30
    • 1970-01-01
    • 2016-06-02
    相关资源
    最近更新 更多