0

我有一个使用 CakeSession 来保存不同用户数据的应用程序。现在我想编写一些默认值,CakeSession::write()并让它们可用于所有视图(也适用于缓存视图)。因此,在呈现视图之前,应该对每个请求进行检查/写入。

但是在哪里放置符合这些要求的代码呢?到目前为止,我尝试了以下位置使用CakeSession::write()但没有成功:

  1. Config/bootstrap.php -> CakeSession 尚未定义
  2. AppController::__construct() -> CakeSession 尚未定义
  3. AppController::beforeFilter() -> 不会为缓存视图调用
4

1 回答 1

0

缓存视图不会在任何地方创建会话。缓存视图根本不初始化请求

文档

It should be noted that once an action is cached, the controller method for the 
action will not be called. When a cache file is created, the request object, 
and view variables are serialized with PHP’s serialize().
于 2012-12-21T21:55:20.650 回答