0

我一直幸福地CakeResponse::disableCache();beforeFilter()of调用AppController.php禁用浏览器缓存,据我所知,它运行良好。

但是,自从升级到 PHP5.4 后,我收到了以下严格警告:

Strict (2048): Non-static method CakeResponse::disableCache() 
should not be called statically, assuming $this from incompatible 
context [APP/Controller/AppController.php, line 53]

该功能似乎仍然有效,但错误告诉我我误解了一些非常基本的东西,并且可能有一种不同的(和更好的)方法来做到这一点。

所以,如果我需要在应用程序范围内禁用浏览器缓存(即:no-store, no-cache, must-revalidate等),那么在 Cake 2.3 中执行此操作的最佳方法是什么?

4

1 回答 1

0

为什么不访问 CakeResponse 对象,它打算如何在 OOP 上下文中使用?作为控制器的一部分:

$this->response

所以在你的情况下:

$this->response->disableCache();

文档中也有很多例子——比如http://book.cakephp.org/2.0/en/controllers/request-response.html#interacting-with-browser-caching

问问题之前你读过这本书吗?

于 2013-02-04T10:57:30.720 回答