0

我在控制器的索引操作上设置了视图缓存,使用

class DiaryController extends AppController {
  ...
  var $cacheAction = array('index' => "+56 hours");

  function index($week = null) {
    ...
  }
}

在以下选项中app/config/core.php

Configure::write('Cache.check', true);

...

Cache::config('default', array('engine' => 'File'));

日记控制器(以及站点的其余部分!)上的索引操作应该只能由经过身份验证的用户访问,使用AuthComponentwith

class AppController extends Controller {

  ...
  var $components = array('Auth', 'Security', 'Session','Cookie','RequestHandler');

  function beforeFilter() {

    $this->Auth->userModel = 'Admin';
    ...
  }
...
}

我想使用将站点的根目录映射到我的登录表单

Router::connect('/', array('controller' => 'admin', 'action' => 'login'));

app/config/routes.php. 一切似乎都正常,直到我注销然后尝试mytestsite.com/diary/index在浏览器中访问。即使我没有登录,我仍然可以访问这些页面。我相信这是缓存的问题,因为我只能访问我有文件的 url app/tmp/cache/views。将索引操作的参数更改$week为我没有缓存文件的值会生成一条You are not authorized to access that location.消息。

奇怪的是,如果我将站点的根目录映射DiaryController

Router::connect('/', array('controller' => 'diary', 'action' => 'index'));

(再次app/config/routes.php)我没有这个问题。当我没有登录时,我无法访问缓存的日记索引视图。

有没有人遇到过这个问题?你能建议我可能错过的东西吗?或者您知道这是否是核心文件中的错误?我正在使用 CakePHP 1.3.15。

4

1 回答 1

1

这是一个较晚的响应,但原因是缓存视图操作会绕过所有控制器和组件回调。Auth 组件通过回调来完成它的工作。因此,当您缓存操作时,这些检查将被忽略。

您可以通过在 $cacheAction 中传递 'callbacks' => true 选项来强制触发回调,如下所示:

public $cacheAction = array(
    'index' => array('callbacks' => true, 'duration' => '+56 hours')
);

但这部分违背了视图缓存的目的,即绕过所有控制器逻辑。

更多信息在这里

于 2012-08-15T20:50:10.137 回答