【问题标题】:CakePHP Auth ignored when accessing cached view with certain routing of '/'使用某些路由“/”访问缓存视图时,CakePHP Auth 被忽略
【发布时间】:2012-07-21 17:58:07
【问题描述】:

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

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'));

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

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。即使我没有登录,我仍然可以访问这些页面。我相信这是缓存的问题,因为我只能访问我在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。

【问题讨论】:

    标签: cakephp authentication caching routes cakephp-1.3


    【解决方案1】:

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

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

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

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

    更多信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      相关资源
      最近更新 更多